{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Your First Elastic Agent\n",
        "\n",
        "This notebook is the API-driven companion to the blog post, **\"Your First Elastic Agent: From a Single Query to an AI-Powered Chat.\"**\n",
        "\n",
        "Here, we'll perform every step from the article—creating a tool, building an agent, and having a conversation—using Python to interact directly with the Agent Builder APIs.\n",
        "\n",
        "### Prerequisites\n",
        "\n",
        "To run this notebook, you will need:\n",
        "* An active Elastic Cloud Serverless Project.\n",
        "  * You can sign up for a free trial at [Elastic Cloud Trial Page](https://cloud.elastic.co/trial)\n",
        "  * Create an `Elasticsearch` type project\n",
        "* The URLs for both Elasticsearch and Kibana\n",
        "  * [How to get ES URL](https://www.elastic.co/docs/solutions/search/search-connection-details#find-cloud-id-serverless)\n",
        "  * For kibana, replace `.es.` in the url with `.kb.` in the ES URL\n",
        "* An API Key with `write` permissions for Elasticsearch and Kibana (same API Key.\n",
        "  * [Doc page showing how to create API Key](https://www.elastic.co/docs/deploy-manage/api-keys/serverless-project-api-keys)"
      ],
      "metadata": {
        "id": "c4XFmWJ1qLdO"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import os\n",
        "\n",
        "# Elasticsearch URL\n",
        "es_url = input(\"Enter your Elasticsearch Endpoint URL: \")\n",
        "# Kibana URL\n",
        "kb_url = es_url.replace(\".es.\", \".kb.\")\n",
        "# Elastic API Key\n",
        "es_api_key = input(\"Enter your Elasticsearch API Key: \")\n",
        "\n",
        "print(\"Using connection details:\")\n",
        "print(f\"Elasticsearch URL: {es_url}\")\n",
        "print(f\"Kibana URL: {kb_url}\")\n",
        "print(f\"ES_API_KEY: ***************************{es_api_key[-5:]}\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "PRYlw3dvxfvH",
        "outputId": "432d5921-58a1-4e5f-d962-694bf68e7e96"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Using connection details:\n",
            "Elasticsearch URL: https://your-first-elastic-agent-a4dc2b.es.us-central1.gcp.elastic.cloud:443\n",
            "Kibana URL: https://your-first-elastic-agent-a4dc2b.kb.us-central1.gcp.elastic.cloud:443\n",
            "ES_API_KEY: ***************************vZw==\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Load Financial Data\n",
        "This section will load synthetic financial data into your Elastic project for use demoing:\n",
        "- Tool creation\n",
        "- Agent creation\n",
        "- Using the agent with the converse api\n",
        "\n",
        "If you have previously loaded the data you can skip this part.\n",
        "\n",
        "If you want to use other data, you will have to adjust the ES|QL queries to match the fields you have, as well as adjust the agent prompt and conversation questions to match your data\n"
      ],
      "metadata": {
        "id": "YvJuXIbQ2IqL"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Clone the repo\n",
        "!git clone https://github.com/jeffvestal/synthetic-financial-data\n",
        "%cd synthetic-financial-data"
      ],
      "metadata": {
        "id": "_5sEty6RE3J4",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "7d72e2aa-99fc-4424-8cd9-0b8b27a8cb39"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Cloning into 'synthetic-financial-data'...\n",
            "remote: Enumerating objects: 368, done.\u001b[K\n",
            "remote: Counting objects: 100% (95/95), done.\u001b[K\n",
            "remote: Compressing objects: 100% (70/70), done.\u001b[K\n",
            "remote: Total 368 (delta 27), reused 72 (delta 20), pack-reused 273 (from 1)\u001b[K\n",
            "Receiving objects: 100% (368/368), 19.93 MiB | 13.48 MiB/s, done.\n",
            "Resolving deltas: 100% (199/199), done.\n",
            "/content/synthetic-financial-data\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Install the python requirements to run the data loading script\n",
        "!pip3 install -qr requirements.txt\n",
        "!pip3 install -qr pandas"
      ],
      "metadata": {
        "id": "DEN3VIC0TqHO",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "f90245d7-5ead-4bb0-9cd9-8db6e57473e2"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "\u001b[?25l   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/937.5 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K   \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m931.8/937.5 kB\u001b[0m \u001b[31m47.8 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m937.5/937.5 kB\u001b[0m \u001b[31m25.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h\u001b[?25l   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/2.0 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m68.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h\u001b[?25l   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/65.1 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m65.1/65.1 kB\u001b[0m \u001b[31m4.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Wait until `.elser-2-elasticsearch` embedding inference endpoint is deployed and ready\n",
        "import time, requests, os\n",
        "\n",
        "# Define request details\n",
        "headers = {\"Authorization\": f\"ApiKey {es_api_key}\", \"Content-Type\": \"application/json\"}\n",
        "url = f\"{es_url}/_inference/sparse_embedding/.elser-2-elasticsearch\"\n",
        "attempt = 0\n",
        "\n",
        "# --- Main Check Loop ---\n",
        "while True:\n",
        "    attempt += 1\n",
        "    print(f\"Polling endpoint... (Attempt #{attempt})\")\n",
        "\n",
        "    try:\n",
        "        # Attempt to connect and raise an exception on failure\n",
        "        requests.post(\n",
        "            url, headers=headers, json={\"input\": \"test\"}, timeout=15\n",
        "        ).raise_for_status()\n",
        "        print(f\"✅ Endpoint is ready.\")\n",
        "        break  # <-- Exit the loop on success\n",
        "\n",
        "    except requests.exceptions.RequestException as e:\n",
        "        status = (\n",
        "            e.response.status_code if e.response is not None else \"N/A\"\n",
        "        )  # Modified line\n",
        "        if e.response is not None and 400 <= status < 500:  # Modified line\n",
        "            # Exit immediately on client errors (e.g., 404 Not Found, 401 Unauthorized)\n",
        "            exit(\n",
        "                f\"❌ Client error ({status}). This is likely a permanent issue. Halting.\"\n",
        "            )\n",
        "\n",
        "        # On any other error (e.g., 503 Service Unavailable), wait and retry\n",
        "        time.sleep(10)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "iMwxERhptQaL",
        "outputId": "da756f9e-f8d0-475a-fd72-dda4105ced47"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Polling endpoint... (Attempt #1)\n",
            "✅ Endpoint is ready.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Load existing data to Elasticsearch. Set timestamps to now\n",
        "\n",
        "os.environ[\"ES_ENDPOINT_URL\"] = es_url\n",
        "os.environ[\"ES_API_KEY\"] = es_api_key\n",
        "!python3 load_all_data.py"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "LKSxziXAaBbn",
        "outputId": "38d33284-ea31-4a4c-c49b-dd51e16d0c49"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "\n",
            "============================================================\n",
            "🚀 FAST DATA LOADER - ALL INDICES\n",
            "============================================================\n",
            "Settings: 1000 batch, 24 workers, timestamps→now\n",
            "Time: 2025-09-23 04:29:02\n",
            "============================================================\n",
            "\n",
            "/usr/local/lib/python3.12/dist-packages/elasticsearch/_sync/client/__init__.py:311: SecurityWarning: Connecting to 'https://your-first-elastic-agent-a4dc2b.es.us-central1.gcp.elastic.cloud:443' using TLS with verify_certs=False is insecure\n",
            "  _transport = transport_class(\n",
            "Elasticsearch client initialized successfully.\n",
            "✓ Connected to Elasticsearch\n",
            "\n",
            "  📁 Accounts: 7,000 documents\n",
            "  📁 Holdings: 122,923 documents\n",
            "  📁 Assets: 183 documents\n",
            "  📁 News: 550 documents\n",
            "  📁 Reports: 120 documents\n",
            "\n",
            "📊 Total: 130,776 documents across 5 indices\n",
            "============================================================\n",
            "\n",
            "⏳ Loading Accounts...Starting: financial_accounts (workers: 24, updating timestamps to current time)\n",
            "Starting: financial_accounts (workers: 24, updating timestamps to current time)\n",
            "Creating index 'financial_accounts'...\n",
            "✓ Successfully created index 'financial_accounts'\n",
            "  Updating timestamps to: 2025-09-23T04:29:03\n",
            "[04:29:05] financial_accounts: batch 1/7 complete (1000 docs, 1000 total)\n",
            "[04:29:05] financial_accounts: batch 2/7 complete (1000 docs, 2000 total)\n",
            "[04:29:05] financial_accounts: batch 3/7 complete (1000 docs, 3000 total)\n",
            "[04:29:05] financial_accounts: batch 4/7 complete (1000 docs, 4000 total)\n",
            "[04:29:05] financial_accounts: batch 5/7 complete (1000 docs, 5000 total)\n",
            "[04:29:05] financial_accounts: batch 6/7 complete (1000 docs, 6000 total)\n",
            "[04:29:05] financial_accounts: batch 7/7 complete (1000 docs, 7000 total)\n",
            " ✓ 2.9s (2439 docs/sec)\n",
            "\n",
            "⏳ Loading Holdings...Starting: financial_holdings (workers: 24, updating timestamps to current time)\n",
            "Starting: financial_holdings (workers: 24, updating timestamps to current time)\n",
            "Creating index 'financial_holdings'...\n",
            "✓ Successfully created index 'financial_holdings'\n",
            "  Updating timestamps to: 2025-09-23T04:29:06\n",
            "[04:29:09] financial_holdings: batch 1/123 complete (1000 docs, 1000 total)\n",
            "[04:29:09] financial_holdings: batch 2/123 complete (1000 docs, 2000 total)\n",
            "[04:29:09] financial_holdings: batch 3/123 complete (1000 docs, 3000 total)\n",
            "[04:29:09] financial_holdings: batch 4/123 complete (1000 docs, 4000 total)\n",
            "[04:29:09] financial_holdings: batch 5/123 complete (1000 docs, 5000 total)\n",
            "[04:29:09] financial_holdings: batch 6/123 complete (1000 docs, 6000 total)\n",
            "[04:29:09] financial_holdings: batch 7/123 complete (1000 docs, 7000 total)\n",
            "[04:29:10] financial_holdings: batch 8/123 complete (1000 docs, 8000 total)\n",
            "[04:29:10] financial_holdings: batch 9/123 complete (1000 docs, 9000 total)\n",
            "[04:29:10] financial_holdings: batch 10/123 complete (1000 docs, 10000 total)\n",
            "[04:29:10] financial_holdings: batch 11/123 complete (1000 docs, 11000 total)\n",
            "[04:29:10] financial_holdings: batch 12/123 complete (1000 docs, 12000 total)\n",
            "[04:29:10] financial_holdings: batch 13/123 complete (1000 docs, 13000 total)\n",
            "[04:29:10] financial_holdings: batch 14/123 complete (1000 docs, 14000 total)\n",
            "[04:29:10] financial_holdings: batch 15/123 complete (1000 docs, 15000 total)\n",
            "[04:29:10] financial_holdings: batch 16/123 complete (1000 docs, 16000 total)\n",
            "[04:29:10] financial_holdings: batch 17/123 complete (1000 docs, 17000 total)\n",
            "[04:29:10] financial_holdings: batch 18/123 complete (1000 docs, 18000 total)\n",
            "[04:29:10] financial_holdings: batch 19/123 complete (1000 docs, 19000 total)\n",
            "[04:29:11] financial_holdings: batch 20/123 complete (1000 docs, 20000 total)\n",
            "[04:29:11] financial_holdings: batch 21/123 complete (1000 docs, 21000 total)\n",
            "[04:29:11] financial_holdings: batch 22/123 complete (1000 docs, 22000 total)\n",
            "[04:29:11] financial_holdings: batch 23/123 complete (1000 docs, 23000 total)\n",
            "[04:29:11] financial_holdings: batch 24/123 complete (1000 docs, 24000 total)\n",
            "[04:29:11] financial_holdings: batch 25/123 complete (1000 docs, 25000 total)\n",
            "[04:29:11] financial_holdings: batch 26/123 complete (1000 docs, 26000 total)\n",
            "[04:29:11] financial_holdings: batch 27/123 complete (1000 docs, 27000 total)\n",
            "[04:29:11] financial_holdings: batch 28/123 complete (1000 docs, 28000 total)\n",
            "[04:29:11] financial_holdings: batch 29/123 complete (1000 docs, 29000 total)\n",
            "[04:29:11] financial_holdings: batch 30/123 complete (1000 docs, 30000 total)\n",
            "[04:29:11] financial_holdings: batch 31/123 complete (1000 docs, 31000 total)\n",
            "[04:29:11] financial_holdings: batch 32/123 complete (1000 docs, 32000 total)\n",
            "[04:29:11] financial_holdings: batch 33/123 complete (1000 docs, 33000 total)\n",
            "[04:29:12] financial_holdings: batch 34/123 complete (1000 docs, 34000 total)\n",
            "[04:29:12] financial_holdings: batch 35/123 complete (1000 docs, 35000 total)\n",
            "[04:29:12] financial_holdings: batch 36/123 complete (1000 docs, 36000 total)\n",
            "[04:29:12] financial_holdings: batch 37/123 complete (1000 docs, 37000 total)\n",
            "[04:29:12] financial_holdings: batch 38/123 complete (1000 docs, 38000 total)\n",
            "[04:29:12] financial_holdings: batch 39/123 complete (1000 docs, 39000 total)\n",
            "[04:29:12] financial_holdings: batch 40/123 complete (1000 docs, 40000 total)\n",
            "[04:29:12] financial_holdings: batch 41/123 complete (1000 docs, 41000 total)\n",
            "[04:29:12] financial_holdings: batch 42/123 complete (1000 docs, 42000 total)\n",
            "[04:29:12] financial_holdings: batch 43/123 complete (1000 docs, 43000 total)\n",
            "[04:29:12] financial_holdings: batch 44/123 complete (1000 docs, 44000 total)\n",
            "[04:29:12] financial_holdings: batch 45/123 complete (1000 docs, 45000 total)\n",
            "[04:29:12] financial_holdings: batch 46/123 complete (1000 docs, 46000 total)\n",
            "[04:29:13] financial_holdings: batch 47/123 complete (1000 docs, 47000 total)\n",
            "[04:29:13] financial_holdings: batch 48/123 complete (1000 docs, 48000 total)\n",
            "[04:29:13] financial_holdings: batch 49/123 complete (1000 docs, 49000 total)\n",
            "[04:29:13] financial_holdings: batch 50/123 complete (1000 docs, 50000 total)\n",
            "[04:29:13] financial_holdings: batch 51/123 complete (1000 docs, 51000 total)\n",
            "[04:29:13] financial_holdings: batch 52/123 complete (1000 docs, 52000 total)\n",
            "[04:29:13] financial_holdings: batch 53/123 complete (1000 docs, 53000 total)\n",
            "[04:29:13] financial_holdings: batch 54/123 complete (1000 docs, 54000 total)\n",
            "[04:29:13] financial_holdings: batch 55/123 complete (1000 docs, 55000 total)\n",
            "[04:29:13] financial_holdings: batch 56/123 complete (1000 docs, 56000 total)\n",
            "[04:29:13] financial_holdings: batch 57/123 complete (1000 docs, 57000 total)\n",
            "[04:29:13] financial_holdings: batch 58/123 complete (1000 docs, 58000 total)\n",
            "[04:29:13] financial_holdings: batch 59/123 complete (1000 docs, 59000 total)\n",
            "[04:29:14] financial_holdings: batch 60/123 complete (1000 docs, 60000 total)\n",
            "[04:29:14] financial_holdings: batch 61/123 complete (1000 docs, 61000 total)\n",
            "[04:29:14] financial_holdings: batch 62/123 complete (1000 docs, 62000 total)\n",
            "[04:29:14] financial_holdings: batch 63/123 complete (1000 docs, 63000 total)\n",
            "[04:29:14] financial_holdings: batch 64/123 complete (1000 docs, 64000 total)\n",
            "[04:29:14] financial_holdings: batch 65/123 complete (1000 docs, 65000 total)\n",
            "[04:29:14] financial_holdings: batch 66/123 complete (1000 docs, 66000 total)\n",
            "[04:29:14] financial_holdings: batch 67/123 complete (1000 docs, 67000 total)\n",
            "[04:29:14] financial_holdings: batch 68/123 complete (1000 docs, 68000 total)\n",
            "[04:29:14] financial_holdings: batch 69/123 complete (1000 docs, 69000 total)\n",
            "[04:29:14] financial_holdings: batch 70/123 complete (1000 docs, 70000 total)\n",
            "[04:29:14] financial_holdings: batch 71/123 complete (1000 docs, 71000 total)\n",
            "[04:29:14] financial_holdings: batch 72/123 complete (1000 docs, 72000 total)\n",
            "[04:29:14] financial_holdings: batch 73/123 complete (1000 docs, 73000 total)\n",
            "[04:29:14] financial_holdings: batch 74/123 complete (1000 docs, 74000 total)\n",
            "[04:29:14] financial_holdings: batch 75/123 complete (1000 docs, 75000 total)\n",
            "[04:29:14] financial_holdings: batch 76/123 complete (1000 docs, 76000 total)\n",
            "[04:29:14] financial_holdings: batch 77/123 complete (1000 docs, 77000 total)\n",
            "[04:29:15] financial_holdings: batch 78/123 complete (1000 docs, 78000 total)\n",
            "[04:29:15] financial_holdings: batch 79/123 complete (1000 docs, 79000 total)\n",
            "[04:29:15] financial_holdings: batch 80/123 complete (1000 docs, 80000 total)\n",
            "[04:29:15] financial_holdings: batch 81/123 complete (1000 docs, 81000 total)\n",
            "[04:29:15] financial_holdings: batch 82/123 complete (1000 docs, 82000 total)\n",
            "[04:29:15] financial_holdings: batch 83/123 complete (1000 docs, 83000 total)\n",
            "[04:29:15] financial_holdings: batch 84/123 complete (1000 docs, 84000 total)\n",
            "[04:29:15] financial_holdings: batch 85/123 complete (1000 docs, 85000 total)\n",
            "[04:29:15] financial_holdings: batch 86/123 complete (1000 docs, 86000 total)\n",
            "[04:29:15] financial_holdings: batch 87/123 complete (1000 docs, 87000 total)\n",
            "[04:29:15] financial_holdings: batch 88/123 complete (1000 docs, 88000 total)\n",
            "[04:29:15] financial_holdings: batch 89/123 complete (1000 docs, 89000 total)\n",
            "[04:29:16] financial_holdings: batch 90/123 complete (1000 docs, 90000 total)\n",
            "[04:29:16] financial_holdings: batch 91/123 complete (1000 docs, 91000 total)\n",
            "[04:29:16] financial_holdings: batch 92/123 complete (1000 docs, 92000 total)\n",
            "[04:29:16] financial_holdings: batch 93/123 complete (1000 docs, 93000 total)\n",
            "[04:29:16] financial_holdings: batch 94/123 complete (1000 docs, 94000 total)\n",
            "[04:29:16] financial_holdings: batch 95/123 complete (1000 docs, 95000 total)\n",
            "[04:29:16] financial_holdings: batch 96/123 complete (1000 docs, 96000 total)\n",
            "[04:29:16] financial_holdings: batch 97/123 complete (1000 docs, 97000 total)\n",
            "[04:29:16] financial_holdings: batch 98/123 complete (1000 docs, 98000 total)\n",
            "[04:29:16] financial_holdings: batch 99/123 complete (1000 docs, 99000 total)\n",
            "[04:29:16] financial_holdings: batch 100/123 complete (1000 docs, 100000 total)\n",
            "[04:29:16] financial_holdings: batch 101/123 complete (1000 docs, 101000 total)\n",
            "[04:29:16] financial_holdings: batch 102/123 complete (1000 docs, 102000 total)\n",
            "[04:29:16] financial_holdings: batch 103/123 complete (1000 docs, 103000 total)\n",
            "[04:29:16] financial_holdings: batch 104/123 complete (1000 docs, 104000 total)\n",
            "[04:29:16] financial_holdings: batch 105/123 complete (1000 docs, 105000 total)\n",
            "[04:29:16] financial_holdings: batch 106/123 complete (1000 docs, 106000 total)\n",
            "[04:29:16] financial_holdings: batch 107/123 complete (1000 docs, 107000 total)\n",
            "[04:29:17] financial_holdings: batch 108/123 complete (1000 docs, 108000 total)\n",
            "[04:29:17] financial_holdings: batch 109/123 complete (1000 docs, 109000 total)\n",
            "[04:29:17] financial_holdings: batch 110/123 complete (1000 docs, 110000 total)\n",
            "[04:29:17] financial_holdings: batch 111/123 complete (1000 docs, 111000 total)\n",
            "[04:29:17] financial_holdings: batch 112/123 complete (1000 docs, 112000 total)\n",
            "[04:29:17] financial_holdings: batch 113/123 complete (1000 docs, 113000 total)\n",
            "[04:29:17] financial_holdings: batch 114/123 complete (1000 docs, 114000 total)\n",
            "[04:29:17] financial_holdings: batch 115/123 complete (1000 docs, 115000 total)\n",
            "[04:29:17] financial_holdings: batch 116/123 complete (1000 docs, 116000 total)\n",
            "[04:29:17] financial_holdings: batch 117/123 complete (1000 docs, 117000 total)\n",
            "[04:29:17] financial_holdings: batch 118/123 complete (1000 docs, 118000 total)\n",
            "[04:29:17] financial_holdings: batch 119/123 complete (1000 docs, 119000 total)\n",
            "[04:29:17] financial_holdings: batch 120/123 complete (1000 docs, 120000 total)\n",
            "[04:29:17] financial_holdings: batch 121/123 complete (923 docs, 120923 total)\n",
            "[04:29:17] financial_holdings: batch 122/123 complete (1000 docs, 121923 total)\n",
            "[04:29:17] financial_holdings: batch 123/123 complete (1000 docs, 122923 total)\n",
            " ✓ 12.4s (9899 docs/sec)\n",
            "\n",
            "⏳ Loading Assets...Starting: financial_asset_details (workers: 24, updating timestamps to current time)\n",
            "Starting: financial_asset_details (workers: 24, updating timestamps to current time)\n",
            "Creating index 'financial_asset_details'...\n",
            "✓ Successfully created index 'financial_asset_details'\n",
            "  Updating timestamps to: 2025-09-23T04:29:18\n",
            "[04:29:28] financial_asset_details: batch 1/1 complete (183 docs, 183 total)\n",
            " ✓ 10.6s (17 docs/sec)\n",
            "\n",
            "⏳ Loading News...Starting: financial_news (workers: 24, updating timestamps to current time)\n",
            "Starting: financial_news (workers: 24, updating timestamps to current time)\n",
            "Creating index 'financial_news'...\n",
            "✓ Successfully created index 'financial_news'\n",
            "  Updating timestamps to: 2025-09-23T04:29:29\n",
            "[04:30:30] financial_news: batch 1/1 FAILED\n",
            " ✓ 61.6s (9 docs/sec)\n",
            "\n",
            "⏳ Loading Reports...Starting: financial_reports (workers: 24, updating timestamps to current time)\n",
            "Starting: financial_reports (workers: 24, updating timestamps to current time)\n",
            "Creating index 'financial_reports'...\n",
            "✓ Successfully created index 'financial_reports'\n",
            "  Updating timestamps to: 2025-09-23T04:30:31\n",
            "[04:31:31] financial_reports: batch 1/1 FAILED\n",
            " ✓ 61.6s (2 docs/sec)\n",
            "\n",
            "============================================================\n",
            "✅ COMPLETE: 5/5 indices loaded\n",
            "⏱️  Total time: 149.1 seconds\n",
            "📈 Average: 877 docs/second\n",
            "🕐 Finished: 04:31:31\n",
            "============================================================\n",
            "\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Check incices are setup and data was loaded\n",
        "!python3 control.py --check-indices"
      ],
      "metadata": {
        "id": "Ov8po55vTltt",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "5e271ca7-0a2f-4c93-c064-7ca14ea189a1"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "🚀 \u001b[34mRunning in non-interactive mode\u001b[0m\u001b[34m...\u001b[0m\n",
            "🔍 \u001b[34mConnecting to Elasticsearch\u001b[0m\u001b[34m...\u001b[0m\n",
            "/usr/local/lib/python3.12/dist-packages/elasticsearch/_sync/client/__init__.py:311: SecurityWarning: Connecting to 'https://your-first-elastic-agent-a4dc2b.es.us-central1.gcp.elastic.cloud:443' using TLS with verify_certs=False is insecure\n",
            "  _transport = transport_class(\n",
            "Elasticsearch client initialized successfully.\n",
            "✅ \u001b[32mConnected to Elasticsearch \u001b[0m\u001b[1;32m8.11\u001b[0m\u001b[32m.\u001b[0m\u001b[1;32m0\u001b[0m\n",
            "\n",
            "\u001b[3m                            📊 Index Status Summary                             \u001b[0m\n",
            "┏━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
            "┃\u001b[1m \u001b[0m\u001b[1mIndex Name           \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mExi…\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mDocum…\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m  Size\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mErrors                     \u001b[0m\u001b[1m \u001b[0m┃\n",
            "┡━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n",
            "│\u001b[36m \u001b[0m\u001b[36mfinancial_asset_deta…\u001b[0m\u001b[36m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m✓   \u001b[0m\u001b[37m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m   183\u001b[0m\u001b[37m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m   N/A\u001b[0m\u001b[37m \u001b[0m│\u001b[31m \u001b[0m\u001b[31m                           \u001b[0m\u001b[31m \u001b[0m│\n",
            "│\u001b[36m \u001b[0m\u001b[36mfinancial_accounts   \u001b[0m\u001b[36m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m✓   \u001b[0m\u001b[37m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m 7,000\u001b[0m\u001b[37m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m   N/A\u001b[0m\u001b[37m \u001b[0m│\u001b[31m \u001b[0m\u001b[31m                           \u001b[0m\u001b[31m \u001b[0m│\n",
            "│\u001b[36m \u001b[0m\u001b[36mfinancial_holdings   \u001b[0m\u001b[36m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m✓   \u001b[0m\u001b[37m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m122,9…\u001b[0m\u001b[37m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m   N/A\u001b[0m\u001b[37m \u001b[0m│\u001b[31m \u001b[0m\u001b[31m                           \u001b[0m\u001b[31m \u001b[0m│\n",
            "│\u001b[36m \u001b[0m\u001b[36mfinancial_news       \u001b[0m\u001b[36m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m✓   \u001b[0m\u001b[37m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m   550\u001b[0m\u001b[37m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m   N/A\u001b[0m\u001b[37m \u001b[0m│\u001b[31m \u001b[0m\u001b[31m                           \u001b[0m\u001b[31m \u001b[0m│\n",
            "│\u001b[36m \u001b[0m\u001b[36mfinancial_reports    \u001b[0m\u001b[36m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m✓   \u001b[0m\u001b[37m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m   120\u001b[0m\u001b[37m \u001b[0m│\u001b[37m \u001b[0m\u001b[37m   N/A\u001b[0m\u001b[37m \u001b[0m│\u001b[31m \u001b[0m\u001b[31m                           \u001b[0m\u001b[31m \u001b[0m│\n",
            "└───────────────────────┴──────┴────────┴────────┴─────────────────────────────┘\n",
            "\n",
            "\u001b[32m✓ All \u001b[0m\u001b[1;32m5\u001b[0m\u001b[32m indices are properly configured\u001b[0m\n",
            "\u001b[2mTotal: \u001b[0m\u001b[1;2;36m130\u001b[0m\u001b[2m,\u001b[0m\u001b[1;2;36m776\u001b[0m\u001b[2m documents \u001b[0m\u001b[1;2m(\u001b[0m\u001b[2msize not available in serverless\u001b[0m\u001b[1;2m)\u001b[0m\n",
            "\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Kibana Setup for Agent Builder"
      ],
      "metadata": {
        "id": "pUZLUZ6y2gGg"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Import necessary libraries\n",
        "import os\n",
        "import json\n",
        "import requests\n",
        "from getpass import getpass  # To securely ask for the API key\n",
        "from IPython.display import display, Markdown, JSON\n",
        "\n",
        "# --- Setup Headers ---\n",
        "HEADERS = {\n",
        "    \"Content-Type\": \"application/json\",\n",
        "    \"kbn-xsrf\": \"true\",\n",
        "    \"Authorization\": f\"ApiKey {es_api_key}\",\n",
        "}\n",
        "\n",
        "# --- Verify Connection ---\n",
        "# Let's make a simple call to the root endpoint to verify our connection and credentials.\n",
        "if not kb_url:\n",
        "    print(\"⚠️ KIBANA_ENDPOINT was not provided. Please provide the endpoint URL.\")\n",
        "else:\n",
        "    try:\n",
        "        response = requests.get(kb_url + \"/api/status\", headers=HEADERS)\n",
        "        response.raise_for_status()  # Raises an exception for bad status codes (4xx or 5xx)\n",
        "\n",
        "        status = response.json()\n",
        "        cluster_name = status.get(\"name\")\n",
        "        version = status.get(\"version\").get(\"number\")\n",
        "\n",
        "        print(f\"✅ Successfully connected to Kibana!\")\n",
        "        print(f\"Cluster Name: {cluster_name}\")\n",
        "        print(f\"Version: {version}\")\n",
        "\n",
        "    except requests.exceptions.RequestException as e:\n",
        "        print(f\"❌ Connection Failed: {e}\")"
      ],
      "metadata": {
        "id": "4yz3J4_DqMps",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "e64b06f4-4c65-455c-e545-03736f848231"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Successfully connected to Kibana!\n",
            "Cluster Name: kb\n",
            "Version: 9.2.0\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "#ONLY BEFORE PUBLIC PREVIEW:\n",
        "You will need to enable Agent Builder in your project.\n",
        "\n",
        "Do to this\n",
        "1. Navigate to `Developer Tools` in Kibana\n",
        "2. Run the following command\n",
        "    ```\n",
        "    POST kbn://internal/kibana/settings\n",
        "    {\n",
        "      \"changes\": {\n",
        "          \"agentBuilder:enabled\": true\n",
        "      }\n",
        "    }\n",
        "    ```\n",
        "3. Refresh your browser\n",
        "\n",
        "You should now see `Agents` in the navigation side bar\n",
        "\n",
        "\n",
        "![CleanShot 2025-09-23 at 10.33.07@2x.png]()\n"
      ],
      "metadata": {
        "id": "IuYaDvcT75d1"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Section 1: The Logic - Testing the ES|QL Query\n",
        "\n",
        "Before we register our logic as a persistent Tool, it's a best practice to test the raw ES|QL query first. This allows us to validate the syntax and confirm it returns the data we expect. We'll use the `/_query` endpoint for this."
      ],
      "metadata": {
        "id": "2D2afJeHqUYz"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# First, let's define our multi-line ES|QL query in a Python string.\n",
        "# This is the same query that will eventually power our custom tool.\n",
        "\n",
        "esql_query = \"\"\"\n",
        "FROM financial_news, financial_reports METADATA _index\n",
        "  | WHERE sentiment == \"negative\"\n",
        "  | WHERE coalesce(published_date, report_date) >= NOW() - TO_TIMEDURATION(?time_duration)\n",
        "  | RENAME primary_symbol AS symbol\n",
        "  | LOOKUP JOIN financial_asset_details ON symbol\n",
        "  | LOOKUP JOIN financial_holdings ON symbol\n",
        "  | LOOKUP JOIN financial_accounts ON account_id\n",
        "  | WHERE account_holder_name IS NOT NULL\n",
        "  | EVAL position_current_value = quantity * current_price.price\n",
        "  | RENAME title AS news_title\n",
        "  | KEEP\n",
        "      account_holder_name, symbol, asset_name, news_title,\n",
        "      sentiment, position_current_value, quantity, current_price.price,\n",
        "      published_date, report_date\n",
        "  | SORT position_current_value DESC\n",
        "  | LIMIT 50\n",
        "\"\"\"\n",
        "\n",
        "print(\"✅ ES|QL query string is defined.\")"
      ],
      "metadata": {
        "id": "Yij22M9Iqize",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "c0caff64-f89a-40f9-dca4-095278120b20"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ ES|QL query string is defined.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Now, we'll construct the JSON body for the API request.\n",
        "# The `params` object is where we provide values for the placeholders in our query string.\n",
        "\n",
        "request_body = {\"query\": esql_query, \"params\": [{\"time_duration\": \"2000 hours\"}]}\n",
        "\n",
        "print(\"✅ Request body is defined with test parameters:\")\n",
        "print(json.dumps(request_body, indent=2))"
      ],
      "metadata": {
        "id": "zJNSVYJhqmNb",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "f78f9d9d-5905-4b12-e3bc-b94e9bc17ed0"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Request body is defined with test parameters:\n",
            "{\n",
            "  \"query\": \"\\nFROM financial_news, financial_reports METADATA _index\\n  | WHERE sentiment == \\\"negative\\\"\\n  | WHERE coalesce(published_date, report_date) >= NOW() - TO_TIMEDURATION(?time_duration)\\n  | RENAME primary_symbol AS symbol\\n  | LOOKUP JOIN financial_asset_details ON symbol\\n  | LOOKUP JOIN financial_holdings ON symbol\\n  | LOOKUP JOIN financial_accounts ON account_id\\n  | WHERE account_holder_name IS NOT NULL\\n  | EVAL position_current_value = quantity * current_price.price\\n  | RENAME title AS news_title\\n  | KEEP\\n      account_holder_name, symbol, asset_name, news_title,\\n      sentiment, position_current_value, quantity, current_price.price,\\n      published_date, report_date\\n  | SORT position_current_value DESC\\n  | LIMIT 50\\n\",\n",
            "  \"params\": [\n",
            "    {\n",
            "      \"time_duration\": \"2000 hours\"\n",
            "    }\n",
            "  ]\n",
            "}\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Finally, let's execute the query and display the results in a clean table using pandas.\n",
        "import pandas as pd\n",
        "\n",
        "# display(Markdown(f\"### 🧪 Testing Query for Symbol: `{request_body['params'][1]['symbol']}`\"))\n",
        "\n",
        "try:\n",
        "    # We use the /_query endpoint to run a raw ES|QL query\n",
        "    response = requests.post(f\"{es_url}/_query\", headers=HEADERS, json=request_body)\n",
        "    response.raise_for_status()\n",
        "\n",
        "    # The response contains column names and rows of values\n",
        "    query_result = response.json()\n",
        "    columns = [col[\"name\"] for col in query_result[\"columns\"]]\n",
        "    # Check for 'values' key if 'rows' is not present\n",
        "    rows = query_result.get(\"rows\", query_result.get(\"values\", []))\n",
        "\n",
        "    # Create and display a pandas DataFrame for a clean table view\n",
        "    df = pd.DataFrame(rows, columns=columns)\n",
        "    display(df)\n",
        "\n",
        "except requests.exceptions.RequestException as e:\n",
        "    print(f\"❌ Query Failed: {e.response.text}\")\n",
        "except KeyError:\n",
        "    print(\"❌ Query executed, but the response format was unexpected.\")\n",
        "    print(\"Raw response:\")\n",
        "    print(response.json())\n",
        "    raise"
      ],
      "metadata": {
        "id": "F5KCf1E-qpu2",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "323408ef-59b4-4d78-d9db-9a8ad21d111f"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "   account_holder_name symbol              asset_name  \\\n",
              "0   Victoria Schneider    TXN  Texas Instruments Inc.   \n",
              "1      Lorraine Gibson    TXN  Texas Instruments Inc.   \n",
              "2        Jillian Davis    TXN  Texas Instruments Inc.   \n",
              "3       Craig Griffith    TXN  Texas Instruments Inc.   \n",
              "4         Jeffrey Byrd    TXN  Texas Instruments Inc.   \n",
              "5         Patrick Rice    TXN  Texas Instruments Inc.   \n",
              "6          Sophia Dean    TXN  Texas Instruments Inc.   \n",
              "7         Sandra Nunez    TXN  Texas Instruments Inc.   \n",
              "8      Brandon Esparza    TXN  Texas Instruments Inc.   \n",
              "9       Miranda Vargas    TXN  Texas Instruments Inc.   \n",
              "10       Eileen Bailey    TXN  Texas Instruments Inc.   \n",
              "11      Misty Gonzalez    TXN  Texas Instruments Inc.   \n",
              "12      Briana Mcclure    TXN  Texas Instruments Inc.   \n",
              "13        James Miller    TXN  Texas Instruments Inc.   \n",
              "14       Reginald Wang    TXN  Texas Instruments Inc.   \n",
              "15     Devin Hernandez    TXN  Texas Instruments Inc.   \n",
              "16       Meghan Parker    TXN  Texas Instruments Inc.   \n",
              "17      Lindsay Harris    TXN  Texas Instruments Inc.   \n",
              "18   Jonathan Sullivan    TXN  Texas Instruments Inc.   \n",
              "19      Stephanie Sosa    TXN  Texas Instruments Inc.   \n",
              "20        Nicole Smith    TXN  Texas Instruments Inc.   \n",
              "21         Jamie Allen    TXN  Texas Instruments Inc.   \n",
              "22        Sharon Brown    TXN  Texas Instruments Inc.   \n",
              "23         Terry Welch    TXN  Texas Instruments Inc.   \n",
              "24         Joshua Shaw    TXN  Texas Instruments Inc.   \n",
              "25      Clinton Greene    TXN  Texas Instruments Inc.   \n",
              "26        Karen Fisher    TXN  Texas Instruments Inc.   \n",
              "27         Angela Horn    TXN  Texas Instruments Inc.   \n",
              "28      Tracy Chambers     GM      General Motors Co.   \n",
              "29          Tonya Bush     GM      General Motors Co.   \n",
              "30     Lauren Hatfield     GM      General Motors Co.   \n",
              "31      Cynthia Harris    TXN  Texas Instruments Inc.   \n",
              "32        David Torres    TXN  Texas Instruments Inc.   \n",
              "33         Stacy Ellis     GM      General Motors Co.   \n",
              "34          Jason Hill    TXN  Texas Instruments Inc.   \n",
              "35       James Edwards     GM      General Motors Co.   \n",
              "36       Douglas Perry     GM      General Motors Co.   \n",
              "37       Amanda Fuller    TXN  Texas Instruments Inc.   \n",
              "38        Crystal Reed    TXN  Texas Instruments Inc.   \n",
              "39     Amber Hernandez     GM      General Motors Co.   \n",
              "40      Madison Harper     GM      General Motors Co.   \n",
              "41     Rebecca Bradley    TXN  Texas Instruments Inc.   \n",
              "42     Tiffany Walters     GM      General Motors Co.   \n",
              "43        Tracy Thomas     GM      General Motors Co.   \n",
              "44       Jose Marshall     GM      General Motors Co.   \n",
              "45      Robert Bennett    TXN  Texas Instruments Inc.   \n",
              "46         Sarah Scott    TXN  Texas Instruments Inc.   \n",
              "47       Hailey Thomas     GM      General Motors Co.   \n",
              "48      George Richard     GM      General Motors Co.   \n",
              "49       Ashley Walton     GM      General Motors Co.   \n",
              "\n",
              "                                           news_title sentiment  \\\n",
              "0   TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "1   TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "2   TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "3   TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "4   TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "5   TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "6   TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "7   TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "8   TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "9   TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "10  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "11  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "12  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "13  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "14  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "15  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "16  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "17  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "18  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "19  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "20  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "21  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "22  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "23  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "24  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "25  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "26  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "27  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "28  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "29  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "30  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "31  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "32  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "33  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "34  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "35  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "36  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "37  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "38  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "39  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "40  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "41  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "42  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "43  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "44  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "45  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "46  TXN Tumbles on Major Cybersecurity Breach, IP ...  negative   \n",
              "47  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "48  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "49  GM Signals Trouble as Economic Slowdown Hits A...  negative   \n",
              "\n",
              "    position_current_value  quantity  current_price.price  \\\n",
              "0            273680.004883     200.0          1368.400024   \n",
              "1            272311.604858     199.0          1368.400024   \n",
              "2            272311.604858     199.0          1368.400024   \n",
              "3            272311.604858     199.0          1368.400024   \n",
              "4            270943.204834     198.0          1368.400024   \n",
              "5            270943.204834     198.0          1368.400024   \n",
              "6            270943.204834     198.0          1368.400024   \n",
              "7            269574.804810     197.0          1368.400024   \n",
              "8            269574.804810     197.0          1368.400024   \n",
              "9            269574.804810     197.0          1368.400024   \n",
              "10           269574.804810     197.0          1368.400024   \n",
              "11           269574.804810     197.0          1368.400024   \n",
              "12           268206.404785     196.0          1368.400024   \n",
              "13           268206.404785     196.0          1368.400024   \n",
              "14           268206.404785     196.0          1368.400024   \n",
              "15           266838.004761     195.0          1368.400024   \n",
              "16           266838.004761     195.0          1368.400024   \n",
              "17           266838.004761     195.0          1368.400024   \n",
              "18           265469.604736     194.0          1368.400024   \n",
              "19           264101.204712     193.0          1368.400024   \n",
              "20           264101.204712     193.0          1368.400024   \n",
              "21           264101.204712     193.0          1368.400024   \n",
              "22           262732.804688     192.0          1368.400024   \n",
              "23           262732.804688     192.0          1368.400024   \n",
              "24           262732.804688     192.0          1368.400024   \n",
              "25           261364.404663     191.0          1368.400024   \n",
              "26           261364.404663     191.0          1368.400024   \n",
              "27           261364.404663     191.0          1368.400024   \n",
              "28           258719.995117     200.0          1293.599976   \n",
              "29           258719.995117     200.0          1293.599976   \n",
              "30           258719.995117     200.0          1293.599976   \n",
              "31           258627.604614     189.0          1368.400024   \n",
              "32           258627.604614     189.0          1368.400024   \n",
              "33           257426.395142     199.0          1293.599976   \n",
              "34           257259.204590     188.0          1368.400024   \n",
              "35           256132.795166     198.0          1293.599976   \n",
              "36           256132.795166     198.0          1293.599976   \n",
              "37           255890.804565     187.0          1368.400024   \n",
              "38           255890.804565     187.0          1368.400024   \n",
              "39           254839.195190     197.0          1293.599976   \n",
              "40           254839.195190     197.0          1293.599976   \n",
              "41           253154.004517     185.0          1368.400024   \n",
              "42           252251.995239     195.0          1293.599976   \n",
              "43           252251.995239     195.0          1293.599976   \n",
              "44           252251.995239     195.0          1293.599976   \n",
              "45           251785.604492     184.0          1368.400024   \n",
              "46           251785.604492     184.0          1368.400024   \n",
              "47           250958.395264     194.0          1293.599976   \n",
              "48           250958.395264     194.0          1293.599976   \n",
              "49           250958.395264     194.0          1293.599976   \n",
              "\n",
              "              published_date report_date  \n",
              "0   2025-09-23T04:29:29.000Z        None  \n",
              "1   2025-09-23T04:29:29.000Z        None  \n",
              "2   2025-09-23T04:29:29.000Z        None  \n",
              "3   2025-09-23T04:29:29.000Z        None  \n",
              "4   2025-09-23T04:29:29.000Z        None  \n",
              "5   2025-09-23T04:29:29.000Z        None  \n",
              "6   2025-09-23T04:29:29.000Z        None  \n",
              "7   2025-09-23T04:29:29.000Z        None  \n",
              "8   2025-09-23T04:29:29.000Z        None  \n",
              "9   2025-09-23T04:29:29.000Z        None  \n",
              "10  2025-09-23T04:29:29.000Z        None  \n",
              "11  2025-09-23T04:29:29.000Z        None  \n",
              "12  2025-09-23T04:29:29.000Z        None  \n",
              "13  2025-09-23T04:29:29.000Z        None  \n",
              "14  2025-09-23T04:29:29.000Z        None  \n",
              "15  2025-09-23T04:29:29.000Z        None  \n",
              "16  2025-09-23T04:29:29.000Z        None  \n",
              "17  2025-09-23T04:29:29.000Z        None  \n",
              "18  2025-09-23T04:29:29.000Z        None  \n",
              "19  2025-09-23T04:29:29.000Z        None  \n",
              "20  2025-09-23T04:29:29.000Z        None  \n",
              "21  2025-09-23T04:29:29.000Z        None  \n",
              "22  2025-09-23T04:29:29.000Z        None  \n",
              "23  2025-09-23T04:29:29.000Z        None  \n",
              "24  2025-09-23T04:29:29.000Z        None  \n",
              "25  2025-09-23T04:29:29.000Z        None  \n",
              "26  2025-09-23T04:29:29.000Z        None  \n",
              "27  2025-09-23T04:29:29.000Z        None  \n",
              "28  2025-09-23T04:29:29.000Z        None  \n",
              "29  2025-09-23T04:29:29.000Z        None  \n",
              "30  2025-09-23T04:29:29.000Z        None  \n",
              "31  2025-09-23T04:29:29.000Z        None  \n",
              "32  2025-09-23T04:29:29.000Z        None  \n",
              "33  2025-09-23T04:29:29.000Z        None  \n",
              "34  2025-09-23T04:29:29.000Z        None  \n",
              "35  2025-09-23T04:29:29.000Z        None  \n",
              "36  2025-09-23T04:29:29.000Z        None  \n",
              "37  2025-09-23T04:29:29.000Z        None  \n",
              "38  2025-09-23T04:29:29.000Z        None  \n",
              "39  2025-09-23T04:29:29.000Z        None  \n",
              "40  2025-09-23T04:29:29.000Z        None  \n",
              "41  2025-09-23T04:29:29.000Z        None  \n",
              "42  2025-09-23T04:29:29.000Z        None  \n",
              "43  2025-09-23T04:29:29.000Z        None  \n",
              "44  2025-09-23T04:29:29.000Z        None  \n",
              "45  2025-09-23T04:29:29.000Z        None  \n",
              "46  2025-09-23T04:29:29.000Z        None  \n",
              "47  2025-09-23T04:29:29.000Z        None  \n",
              "48  2025-09-23T04:29:29.000Z        None  \n",
              "49  2025-09-23T04:29:29.000Z        None  "
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-c00617df-7de8-403d-be85-7573d0f2df7d\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>account_holder_name</th>\n",
              "      <th>symbol</th>\n",
              "      <th>asset_name</th>\n",
              "      <th>news_title</th>\n",
              "      <th>sentiment</th>\n",
              "      <th>position_current_value</th>\n",
              "      <th>quantity</th>\n",
              "      <th>current_price.price</th>\n",
              "      <th>published_date</th>\n",
              "      <th>report_date</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Victoria Schneider</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>273680.004883</td>\n",
              "      <td>200.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Lorraine Gibson</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>272311.604858</td>\n",
              "      <td>199.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Jillian Davis</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>272311.604858</td>\n",
              "      <td>199.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Craig Griffith</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>272311.604858</td>\n",
              "      <td>199.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Jeffrey Byrd</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>270943.204834</td>\n",
              "      <td>198.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>Patrick Rice</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>270943.204834</td>\n",
              "      <td>198.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>Sophia Dean</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>270943.204834</td>\n",
              "      <td>198.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>Sandra Nunez</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>269574.804810</td>\n",
              "      <td>197.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>Brandon Esparza</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>269574.804810</td>\n",
              "      <td>197.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>Miranda Vargas</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>269574.804810</td>\n",
              "      <td>197.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>Eileen Bailey</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>269574.804810</td>\n",
              "      <td>197.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>Misty Gonzalez</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>269574.804810</td>\n",
              "      <td>197.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>Briana Mcclure</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>268206.404785</td>\n",
              "      <td>196.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>James Miller</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>268206.404785</td>\n",
              "      <td>196.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>Reginald Wang</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>268206.404785</td>\n",
              "      <td>196.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>Devin Hernandez</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>266838.004761</td>\n",
              "      <td>195.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>Meghan Parker</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>266838.004761</td>\n",
              "      <td>195.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>Lindsay Harris</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>266838.004761</td>\n",
              "      <td>195.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>Jonathan Sullivan</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>265469.604736</td>\n",
              "      <td>194.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19</th>\n",
              "      <td>Stephanie Sosa</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>264101.204712</td>\n",
              "      <td>193.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20</th>\n",
              "      <td>Nicole Smith</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>264101.204712</td>\n",
              "      <td>193.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>21</th>\n",
              "      <td>Jamie Allen</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>264101.204712</td>\n",
              "      <td>193.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>22</th>\n",
              "      <td>Sharon Brown</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>262732.804688</td>\n",
              "      <td>192.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>23</th>\n",
              "      <td>Terry Welch</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>262732.804688</td>\n",
              "      <td>192.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>24</th>\n",
              "      <td>Joshua Shaw</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>262732.804688</td>\n",
              "      <td>192.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25</th>\n",
              "      <td>Clinton Greene</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>261364.404663</td>\n",
              "      <td>191.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>26</th>\n",
              "      <td>Karen Fisher</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>261364.404663</td>\n",
              "      <td>191.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>27</th>\n",
              "      <td>Angela Horn</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>261364.404663</td>\n",
              "      <td>191.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>28</th>\n",
              "      <td>Tracy Chambers</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>258719.995117</td>\n",
              "      <td>200.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>29</th>\n",
              "      <td>Tonya Bush</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>258719.995117</td>\n",
              "      <td>200.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>30</th>\n",
              "      <td>Lauren Hatfield</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>258719.995117</td>\n",
              "      <td>200.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>31</th>\n",
              "      <td>Cynthia Harris</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>258627.604614</td>\n",
              "      <td>189.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>32</th>\n",
              "      <td>David Torres</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>258627.604614</td>\n",
              "      <td>189.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>33</th>\n",
              "      <td>Stacy Ellis</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>257426.395142</td>\n",
              "      <td>199.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>34</th>\n",
              "      <td>Jason Hill</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>257259.204590</td>\n",
              "      <td>188.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>35</th>\n",
              "      <td>James Edwards</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>256132.795166</td>\n",
              "      <td>198.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>36</th>\n",
              "      <td>Douglas Perry</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>256132.795166</td>\n",
              "      <td>198.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>37</th>\n",
              "      <td>Amanda Fuller</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>255890.804565</td>\n",
              "      <td>187.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>38</th>\n",
              "      <td>Crystal Reed</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>255890.804565</td>\n",
              "      <td>187.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>39</th>\n",
              "      <td>Amber Hernandez</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>254839.195190</td>\n",
              "      <td>197.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>40</th>\n",
              "      <td>Madison Harper</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>254839.195190</td>\n",
              "      <td>197.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>41</th>\n",
              "      <td>Rebecca Bradley</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>253154.004517</td>\n",
              "      <td>185.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>42</th>\n",
              "      <td>Tiffany Walters</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>252251.995239</td>\n",
              "      <td>195.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>43</th>\n",
              "      <td>Tracy Thomas</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>252251.995239</td>\n",
              "      <td>195.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>44</th>\n",
              "      <td>Jose Marshall</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>252251.995239</td>\n",
              "      <td>195.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>45</th>\n",
              "      <td>Robert Bennett</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>251785.604492</td>\n",
              "      <td>184.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>46</th>\n",
              "      <td>Sarah Scott</td>\n",
              "      <td>TXN</td>\n",
              "      <td>Texas Instruments Inc.</td>\n",
              "      <td>TXN Tumbles on Major Cybersecurity Breach, IP ...</td>\n",
              "      <td>negative</td>\n",
              "      <td>251785.604492</td>\n",
              "      <td>184.0</td>\n",
              "      <td>1368.400024</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>47</th>\n",
              "      <td>Hailey Thomas</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>250958.395264</td>\n",
              "      <td>194.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>48</th>\n",
              "      <td>George Richard</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>250958.395264</td>\n",
              "      <td>194.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>49</th>\n",
              "      <td>Ashley Walton</td>\n",
              "      <td>GM</td>\n",
              "      <td>General Motors Co.</td>\n",
              "      <td>GM Signals Trouble as Economic Slowdown Hits A...</td>\n",
              "      <td>negative</td>\n",
              "      <td>250958.395264</td>\n",
              "      <td>194.0</td>\n",
              "      <td>1293.599976</td>\n",
              "      <td>2025-09-23T04:29:29.000Z</td>\n",
              "      <td>None</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-c00617df-7de8-403d-be85-7573d0f2df7d')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-c00617df-7de8-403d-be85-7573d0f2df7d button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-c00617df-7de8-403d-be85-7573d0f2df7d');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "    <div id=\"df-7ef30e5a-8435-4bb8-845f-9c9cd890fe5c\">\n",
              "      <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-7ef30e5a-8435-4bb8-845f-9c9cd890fe5c')\"\n",
              "                title=\"Suggest charts\"\n",
              "                style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "      </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "      <script>\n",
              "        async function quickchart(key) {\n",
              "          const quickchartButtonEl =\n",
              "            document.querySelector('#' + key + ' button');\n",
              "          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "          quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "          try {\n",
              "            const charts = await google.colab.kernel.invokeFunction(\n",
              "                'suggestCharts', [key], {});\n",
              "          } catch (error) {\n",
              "            console.error('Error during call to suggestCharts:', error);\n",
              "          }\n",
              "          quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "          quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "        }\n",
              "        (() => {\n",
              "          let quickchartButtonEl =\n",
              "            document.querySelector('#df-7ef30e5a-8435-4bb8-845f-9c9cd890fe5c button');\n",
              "          quickchartButtonEl.style.display =\n",
              "            google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "        })();\n",
              "      </script>\n",
              "    </div>\n",
              "\n",
              "  <div id=\"id_54c9155b-a047-4447-87d3-95a3637f4c88\">\n",
              "    <style>\n",
              "      .colab-df-generate {\n",
              "        background-color: #E8F0FE;\n",
              "        border: none;\n",
              "        border-radius: 50%;\n",
              "        cursor: pointer;\n",
              "        display: none;\n",
              "        fill: #1967D2;\n",
              "        height: 32px;\n",
              "        padding: 0 0 0 0;\n",
              "        width: 32px;\n",
              "      }\n",
              "\n",
              "      .colab-df-generate:hover {\n",
              "        background-color: #E2EBFA;\n",
              "        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "        fill: #174EA6;\n",
              "      }\n",
              "\n",
              "      [theme=dark] .colab-df-generate {\n",
              "        background-color: #3B4455;\n",
              "        fill: #D2E3FC;\n",
              "      }\n",
              "\n",
              "      [theme=dark] .colab-df-generate:hover {\n",
              "        background-color: #434B5C;\n",
              "        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "        fill: #FFFFFF;\n",
              "      }\n",
              "    </style>\n",
              "    <button class=\"colab-df-generate\" onclick=\"generateWithVariable('df')\"\n",
              "            title=\"Generate code using this dataframe.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "    <script>\n",
              "      (() => {\n",
              "      const buttonEl =\n",
              "        document.querySelector('#id_54c9155b-a047-4447-87d3-95a3637f4c88 button.colab-df-generate');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      buttonEl.onclick = () => {\n",
              "        google.colab.notebook.generateWithVariable('df');\n",
              "      }\n",
              "      })();\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "dataframe",
              "variable_name": "df",
              "repr_error": "Out of range float values are not JSON compliant: nan"
            }
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Section 2: The Skill - Creating the Custom Tool\n",
        "\n",
        "Now that we've validated our query, it's time to register it as a persistent **Tool**. This makes our logic available to any AI agent.\n",
        "\n",
        "The most important parts of this definition are the `description` fields. The main `description` tells the agent *what the tool does*, and the parameter descriptions explain *what kind of information the tool needs* to run. The LLM uses this text to decide when and how to use our tool."
      ],
      "metadata": {
        "id": "q37akGUmrf0e"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# First, let's define the full JSON payload for our new tool.\n",
        "# This includes its ID, a description for the LLM, the ES|QL query, and the parameter schema.\n",
        "\n",
        "tool_id = \"find_client_exposure_to_negative_news\"\n",
        "\n",
        "tool_definition = {\n",
        "    \"id\": tool_id,\n",
        "    \"type\": \"esql\",\n",
        "    \"description\": \"Finds client portfolio exposure to negative news. This tool scans recent news and reports for negative sentiment, identifies the associated asset, and finds all clients holding that asset. It returns a list sorted by the current market value of the position to highlight the highest potential risk.\",\n",
        "    \"configuration\": {\n",
        "        \"query\": \"\"\"\n",
        "        FROM financial_news, financial_reports METADATA _index\n",
        "        | WHERE sentiment == \"negative\"\n",
        "        | WHERE coalesce(published_date, report_date) >= NOW() - TO_TIMEDURATION(?time_duration)\n",
        "        | RENAME primary_symbol AS symbol\n",
        "        | LOOKUP JOIN financial_asset_details ON symbol\n",
        "        | LOOKUP JOIN financial_holdings ON symbol\n",
        "        | LOOKUP JOIN financial_accounts ON account_id\n",
        "        | WHERE account_holder_name IS NOT NULL\n",
        "        | EVAL position_current_value = quantity * current_price.price\n",
        "        | RENAME title AS news_title\n",
        "        | KEEP\n",
        "            account_holder_name, symbol, asset_name, news_title,\n",
        "            sentiment, position_current_value, quantity, current_price.price,\n",
        "            published_date, report_date\n",
        "        | SORT position_current_value DESC\n",
        "        | LIMIT 50\n",
        "      \"\"\",\n",
        "        \"params\": {\n",
        "            \"time_duration\": {\n",
        "                \"type\": \"keyword\",\n",
        "                \"description\": \"\"\"The timeframe to search back for negative news. Format is \"X hours\" DEFAULT TO 8760 hours \"\"\",\n",
        "            }\n",
        "        },\n",
        "    },\n",
        "    \"tags\": [\"retrieval\", \"risk-analysis\"],\n",
        "}\n",
        "\n",
        "\n",
        "print(f\"✅ Tool definition for '{tool_id}' is ready.\")\n",
        "# Displaying the JSON we are about to send\n",
        "display(JSON(tool_definition))"
      ],
      "metadata": {
        "id": "VOateXc8roqx",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 481
        },
        "outputId": "45aaea0b-8ba5-463d-bcb0-25932c26ead1"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Tool definition for 'find_client_exposure_to_negative_news' is ready.\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.JSON object>"
            ],
            "application/json": {
              "id": "find_client_exposure_to_negative_news",
              "type": "esql",
              "description": "Finds client portfolio exposure to negative news. This tool scans recent news and reports for negative sentiment, identifies the associated asset, and finds all clients holding that asset. It returns a list sorted by the current market value of the position to highlight the highest potential risk.",
              "configuration": {
                "query": "\n        FROM financial_news, financial_reports METADATA _index\n        | WHERE sentiment == \"negative\"\n        | WHERE coalesce(published_date, report_date) >= NOW() - TO_TIMEDURATION(?time_duration)\n        | RENAME primary_symbol AS symbol\n        | LOOKUP JOIN financial_asset_details ON symbol\n        | LOOKUP JOIN financial_holdings ON symbol\n        | LOOKUP JOIN financial_accounts ON account_id\n        | WHERE account_holder_name IS NOT NULL\n        | EVAL position_current_value = quantity * current_price.price\n        | RENAME title AS news_title\n        | KEEP\n            account_holder_name, symbol, asset_name, news_title,\n            sentiment, position_current_value, quantity, current_price.price,\n            published_date, report_date\n        | SORT position_current_value DESC\n        | LIMIT 50\n      ",
                "params": {
                  "time_duration": {
                    "type": "keyword",
                    "description": "The timeframe to search back for negative news. Format is \"X hours\" DEFAULT TO 8760 hours "
                  }
                }
              },
              "tags": [
                "retrieval",
                "risk-analysis"
              ]
            }
          },
          "metadata": {
            "application/json": {
              "expanded": false,
              "root": "root"
            }
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Now, let's create the tool by sending a POST request to the /api/chat/tools endpoint.\n",
        "\n",
        "display(Markdown(f\"Create Tool: `{tool_id}`\"))\n",
        "\n",
        "try:\n",
        "    # Note that Kibana API endpoints are prefixed with kbn:// but accessed via the standard HTTP endpoint\n",
        "    response = requests.post(\n",
        "        f\"{kb_url}/api/agent_builder/tools\", headers=HEADERS, json=tool_definition\n",
        "    )\n",
        "    response.raise_for_status()\n",
        "\n",
        "    print(f\"✅ Successfully created the tool!\")\n",
        "    # Display the server's response\n",
        "    display(JSON(response.json()))\n",
        "\n",
        "except requests.exceptions.RequestException as e:\n",
        "    # Handle cases where the tool might already exist or other errors\n",
        "    if (\n",
        "        e.response.status_code == 400\n",
        "        and \"Tool with id\" in e.response.text\n",
        "        and \"already exists\" in e.response.text\n",
        "    ):\n",
        "        print(f\"⚠️ Tool with ID '{tool_id}' already exists. Continuing.\")\n",
        "    else:\n",
        "        print(f\"❌ Tool creation failed: {e.response.text}\")"
      ],
      "metadata": {
        "id": "Uc-aYgXqrrrH",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 797
        },
        "outputId": "bf9aea59-fe85-4386-f152-94a7f66cbc87"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Create Tool: `find_client_exposure_to_negative_news`"
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Successfully created the tool!\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.JSON object>"
            ],
            "application/json": {
              "id": "find_client_exposure_to_negative_news",
              "type": "esql",
              "description": "Finds client portfolio exposure to negative news. This tool scans recent news and reports for negative sentiment, identifies the associated asset, and finds all clients holding that asset. It returns a list sorted by the current market value of the position to highlight the highest potential risk.",
              "tags": [
                "retrieval",
                "risk-analysis"
              ],
              "configuration": {
                "query": "\n        FROM financial_news, financial_reports METADATA _index\n        | WHERE sentiment == \"negative\"\n        | WHERE coalesce(published_date, report_date) >= NOW() - TO_TIMEDURATION(?time_duration)\n        | RENAME primary_symbol AS symbol\n        | LOOKUP JOIN financial_asset_details ON symbol\n        | LOOKUP JOIN financial_holdings ON symbol\n        | LOOKUP JOIN financial_accounts ON account_id\n        | WHERE account_holder_name IS NOT NULL\n        | EVAL position_current_value = quantity * current_price.price\n        | RENAME title AS news_title\n        | KEEP\n            account_holder_name, symbol, asset_name, news_title,\n            sentiment, position_current_value, quantity, current_price.price,\n            published_date, report_date\n        | SORT position_current_value DESC\n        | LIMIT 50\n      ",
                "params": {
                  "time_duration": {
                    "type": "keyword",
                    "description": "The timeframe to search back for negative news. Format is \"X hours\" DEFAULT TO 8760 hours "
                  }
                }
              },
              "readonly": false,
              "schema": {
                "type": "object",
                "properties": {
                  "time_duration": {
                    "type": "string",
                    "description": "The timeframe to search back for negative news. Format is \"X hours\" DEFAULT TO 8760 hours "
                  }
                },
                "required": [
                  "time_duration"
                ],
                "additionalProperties": false,
                "description": "Parameters needed to execute the query",
                "$schema": "http://json-schema.org/draft-07/schema#"
              }
            }
          },
          "metadata": {
            "application/json": {
              "expanded": false,
              "root": "root"
            }
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Finally, let's verify the tool was created by fetching it directly by its ID.\n",
        "\n",
        "display(Markdown(f\"### 🔍 Verifying Tool: `{tool_id}`\"))\n",
        "\n",
        "try:\n",
        "    response = requests.get(\n",
        "        f\"{kb_url}/api/agent_builder/tools/{tool_id}\", headers=HEADERS\n",
        "    )\n",
        "    response.raise_for_status()\n",
        "\n",
        "    print(\"✅ Tool exists! Details below:\")\n",
        "    display(JSON(response.json()))\n",
        "\n",
        "except requests.exceptions.RequestException as e:\n",
        "    print(f\"❌ Could not retrieve tool: {e.response.text}\")"
      ],
      "metadata": {
        "id": "KcBKZ6hjruPO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 808
        },
        "outputId": "72802df2-b59b-4c3b-8a3f-f1b30ea086b7"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "### 🔍 Verifying Tool: `find_client_exposure_to_negative_news`"
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Tool exists! Details below:\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.JSON object>"
            ],
            "application/json": {
              "id": "find_client_exposure_to_negative_news",
              "type": "esql",
              "description": "Finds client portfolio exposure to negative news. This tool scans recent news and reports for negative sentiment, identifies the associated asset, and finds all clients holding that asset. It returns a list sorted by the current market value of the position to highlight the highest potential risk.",
              "tags": [
                "retrieval",
                "risk-analysis"
              ],
              "configuration": {
                "query": "\n        FROM financial_news, financial_reports METADATA _index\n        | WHERE sentiment == \"negative\"\n        | WHERE coalesce(published_date, report_date) >= NOW() - TO_TIMEDURATION(?time_duration)\n        | RENAME primary_symbol AS symbol\n        | LOOKUP JOIN financial_asset_details ON symbol\n        | LOOKUP JOIN financial_holdings ON symbol\n        | LOOKUP JOIN financial_accounts ON account_id\n        | WHERE account_holder_name IS NOT NULL\n        | EVAL position_current_value = quantity * current_price.price\n        | RENAME title AS news_title\n        | KEEP\n            account_holder_name, symbol, asset_name, news_title,\n            sentiment, position_current_value, quantity, current_price.price,\n            published_date, report_date\n        | SORT position_current_value DESC\n        | LIMIT 50\n      ",
                "params": {
                  "time_duration": {
                    "type": "keyword",
                    "description": "The timeframe to search back for negative news. Format is \"X hours\" DEFAULT TO 8760 hours "
                  }
                }
              },
              "readonly": false,
              "schema": {
                "type": "object",
                "properties": {
                  "time_duration": {
                    "type": "string",
                    "description": "The timeframe to search back for negative news. Format is \"X hours\" DEFAULT TO 8760 hours "
                  }
                },
                "required": [
                  "time_duration"
                ],
                "additionalProperties": false,
                "description": "Parameters needed to execute the query",
                "$schema": "http://json-schema.org/draft-07/schema#"
              }
            }
          },
          "metadata": {
            "application/json": {
              "expanded": false,
              "root": "root"
            }
          }
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Section 3: The Brains - Creating the Custom Agent\n",
        "\n",
        "With our \"skill\" (the Tool) created, we now need to create the \"brain\" (the **Agent**). The Agent is the persona that combines the power of an LLM with a specific set of tools and, most importantly, a set of \"Custom Instructions.\"\n",
        "\n",
        "These instructions act as the agent's constitution. They define its personality, its mission, and the rules it must follow. A well-crafted prompt is the key to creating a reliable and specialized assistant."
      ],
      "metadata": {
        "id": "n2voaqVqrx2E"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# First, let's define the detailed instructions for our \"Financial Manager\" agent.\n",
        "# This prompt tells the agent who it is, what it should do, and what it absolutely should NOT do.\n",
        "\n",
        "financial_assistant_prompt = \"\"\"\n",
        "You are a specialized Data Intelligence Assistant for financial managers, designed to provide precise, data-driven insights from information stored in Elasticsearch.\n",
        "\n",
        "**Your Core Mission:**\n",
        "- Respond accurately and concisely to natural language queries from financial managers.\n",
        "- Provide precise, objective, and actionable information derived solely from the Elasticsearch data at your disposal.\n",
        "- Summarize key data points and trends based on user requests.\n",
        "\n",
        "**Reasoning Framework:**\n",
        "1.  **Understand:** Deconstruct the user's query to understand their core intent.\n",
        "2.  **Plan:** Formulate a step-by-step plan to answer the question. If you are unsure about the data structure, use the available tools to explore the indices first.\n",
        "3.  **Execute:** Use the available tools to execute your plan.\n",
        "4.  **Synthesize:** Combine the information from all tool calls into a single, comprehensive, and easy-to-read answer.\n",
        "\n",
        "**Key Directives and Constraints:**\n",
        "- **If a user's request is ambiguous, ask clarifying questions before proceeding.**\n",
        "- **DO NOT provide financial advice, recommendations, or predictions.** Your role is strictly informational and analytical.\n",
        "- Stay strictly on topic with financial data queries.\n",
        "- If you cannot answer a query, state that clearly and offer alternative ways you might help *within your data scope*.\n",
        "- All numerical values should be formatted appropriately (e.g., currency, percentages).\n",
        "\n",
        "**Output Format:**\n",
        "- All responses must be formatted using **Markdown** for clarity.\n",
        "- When presenting structured data, use Markdown tables, lists, or bolding.\n",
        "\n",
        "**Start by greeting the financial manager and offering assistance.**\n",
        "\"\"\"\n",
        "\n",
        "print(\"✅ Agent prompt is defined.\")"
      ],
      "metadata": {
        "id": "zzAIKcv9r2H7",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "2d481347-cce1-40aa-efde-669349171605"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Agent prompt is defined.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Now, let's define the full agent payload.\n",
        "# We'll give it an ID, a name, and a configuration that includes our prompt and access to our ES|QL tools.\n",
        "\n",
        "agent_id = \"financial_assistant\"\n",
        "\n",
        "agent_definition = {\n",
        "    \"id\": agent_id,\n",
        "    \"name\": \"Financial Assistant\",\n",
        "    \"description\": \"An assistant for analyzing and understanding your financial data\",\n",
        "    \"labels\": [\"Finance\"],\n",
        "    \"avatar_color\": \"#16C5C0\",\n",
        "    \"avatar_symbol\": \"💰\",\n",
        "    \"configuration\": {\n",
        "        \"instructions\": financial_assistant_prompt,\n",
        "        \"tools\": [\n",
        "            {\n",
        "                \"tool_ids\": [\n",
        "                    \"platform.core.search\",\n",
        "                    \"platform.core.list_indices\",\n",
        "                    \"platform.core.get_index_mapping\",\n",
        "                    \"platform.core.get_document_by_id\",\n",
        "                    \"find_client_exposure_to_negative_news\",\n",
        "                ]\n",
        "            }\n",
        "        ],\n",
        "    },\n",
        "}\n",
        "\n",
        "print(f\"✅ Agent definition for '{agent_id}' is ready.\")\n",
        "display(JSON(agent_definition))"
      ],
      "metadata": {
        "id": "ItkekBHcr4T5",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 660
        },
        "outputId": "ec3c564f-bffc-40bc-eb31-4f52cbc0d082"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Agent definition for 'financial_assistant' is ready.\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.JSON object>"
            ],
            "application/json": {
              "id": "financial_assistant",
              "name": "Financial Assistant",
              "description": "An assistant for analyzing and understanding your financial data",
              "labels": [
                "Finance"
              ],
              "avatar_color": "#16C5C0",
              "avatar_symbol": "💰",
              "configuration": {
                "instructions": "\nYou are a specialized Data Intelligence Assistant for financial managers, designed to provide precise, data-driven insights from information stored in Elasticsearch.\n\n**Your Core Mission:**\n- Respond accurately and concisely to natural language queries from financial managers.\n- Provide precise, objective, and actionable information derived solely from the Elasticsearch data at your disposal.\n- Summarize key data points and trends based on user requests.\n\n**Reasoning Framework:**\n1.  **Understand:** Deconstruct the user's query to understand their core intent.\n2.  **Plan:** Formulate a step-by-step plan to answer the question. If you are unsure about the data structure, use the available tools to explore the indices first.\n3.  **Execute:** Use the available tools to execute your plan.\n4.  **Synthesize:** Combine the information from all tool calls into a single, comprehensive, and easy-to-read answer.\n\n**Key Directives and Constraints:**\n- **If a user's request is ambiguous, ask clarifying questions before proceeding.**\n- **DO NOT provide financial advice, recommendations, or predictions.** Your role is strictly informational and analytical.\n- Stay strictly on topic with financial data queries.\n- If you cannot answer a query, state that clearly and offer alternative ways you might help *within your data scope*.\n- All numerical values should be formatted appropriately (e.g., currency, percentages).\n\n**Output Format:**\n- All responses must be formatted using **Markdown** for clarity.\n- When presenting structured data, use Markdown tables, lists, or bolding.\n\n**Start by greeting the financial manager and offering assistance.**\n",
                "tools": [
                  {
                    "tool_ids": [
                      "platform.core.search",
                      "platform.core.list_indices",
                      "platform.core.get_index_mapping",
                      "platform.core.get_document_by_id",
                      "find_client_exposure_to_negative_news"
                    ]
                  }
                ]
              }
            }
          },
          "metadata": {
            "application/json": {
              "expanded": false,
              "root": "root"
            }
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Create the agent by sending a POST request to the /api/chat/agents endpoint.\n",
        "\n",
        "display(Markdown(f\"### 🤖 Creating Agent: `{agent_id}`\"))\n",
        "\n",
        "try:\n",
        "    response = requests.post(\n",
        "        f\"{kb_url}/api/agent_builder/agents\", headers=HEADERS, json=agent_definition\n",
        "    )\n",
        "    response.raise_for_status()\n",
        "\n",
        "    print(f\"✅ Successfully created the agent!\")\n",
        "    display(JSON(response.json()))\n",
        "\n",
        "except requests.exceptions.RequestException as e:\n",
        "    if e.response.status_code == 409:\n",
        "        print(f\"⚠️ Agent with ID '{agent_id}' already exists. Continuing.\")\n",
        "    else:\n",
        "        print(f\"❌ Agent creation failed: {e.response.text}\")"
      ],
      "metadata": {
        "id": "lvIESp2Ir7qC",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 718
        },
        "outputId": "85f86437-0ad3-4d12-cb65-9083c3458217"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "### 🤖 Creating Agent: `financial_assistant`"
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Successfully created the agent!\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.JSON object>"
            ],
            "application/json": {
              "id": "financial_assistant",
              "type": "chat",
              "name": "Financial Assistant",
              "description": "An assistant for analyzing and understanding your financial data",
              "labels": [
                "Finance"
              ],
              "avatar_color": "#16C5C0",
              "avatar_symbol": "💰",
              "configuration": {
                "instructions": "\nYou are a specialized Data Intelligence Assistant for financial managers, designed to provide precise, data-driven insights from information stored in Elasticsearch.\n\n**Your Core Mission:**\n- Respond accurately and concisely to natural language queries from financial managers.\n- Provide precise, objective, and actionable information derived solely from the Elasticsearch data at your disposal.\n- Summarize key data points and trends based on user requests.\n\n**Reasoning Framework:**\n1.  **Understand:** Deconstruct the user's query to understand their core intent.\n2.  **Plan:** Formulate a step-by-step plan to answer the question. If you are unsure about the data structure, use the available tools to explore the indices first.\n3.  **Execute:** Use the available tools to execute your plan.\n4.  **Synthesize:** Combine the information from all tool calls into a single, comprehensive, and easy-to-read answer.\n\n**Key Directives and Constraints:**\n- **If a user's request is ambiguous, ask clarifying questions before proceeding.**\n- **DO NOT provide financial advice, recommendations, or predictions.** Your role is strictly informational and analytical.\n- Stay strictly on topic with financial data queries.\n- If you cannot answer a query, state that clearly and offer alternative ways you might help *within your data scope*.\n- All numerical values should be formatted appropriately (e.g., currency, percentages).\n\n**Output Format:**\n- All responses must be formatted using **Markdown** for clarity.\n- When presenting structured data, use Markdown tables, lists, or bolding.\n\n**Start by greeting the financial manager and offering assistance.**\n",
                "tools": [
                  {
                    "tool_ids": [
                      "platform.core.search",
                      "platform.core.list_indices",
                      "platform.core.get_index_mapping",
                      "platform.core.get_document_by_id",
                      "find_client_exposure_to_negative_news"
                    ]
                  }
                ]
              }
            }
          },
          "metadata": {
            "application/json": {
              "expanded": false,
              "root": "root"
            }
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Finally, let's verify the agent was created by fetching it directly by its ID.\n",
        "\n",
        "display(Markdown(f\"### 🔍 Verifying Agent: `{agent_id}`\"))\n",
        "\n",
        "try:\n",
        "    response = requests.get(\n",
        "        f\"{kb_url}/api/agent_builder/agents/{agent_id}\", headers=HEADERS\n",
        "    )\n",
        "    response.raise_for_status()\n",
        "\n",
        "    print(\"✅ Agent exists! Details below:\")\n",
        "    display(JSON(response.json()))\n",
        "\n",
        "except requests.exceptions.RequestException as e:\n",
        "    print(f\"❌ Could not retrieve agent: {e.response.text}\")"
      ],
      "metadata": {
        "id": "bbggcUOIr8NT",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 718
        },
        "outputId": "d56e7519-575e-429d-ddd4-7806ca5f6dcd"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "### 🔍 Verifying Agent: `financial_assistant`"
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Agent exists! Details below:\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.JSON object>"
            ],
            "application/json": {
              "id": "financial_assistant",
              "type": "chat",
              "name": "Financial Assistant",
              "description": "An assistant for analyzing and understanding your financial data",
              "labels": [
                "Finance"
              ],
              "avatar_color": "#16C5C0",
              "avatar_symbol": "💰",
              "configuration": {
                "instructions": "\nYou are a specialized Data Intelligence Assistant for financial managers, designed to provide precise, data-driven insights from information stored in Elasticsearch.\n\n**Your Core Mission:**\n- Respond accurately and concisely to natural language queries from financial managers.\n- Provide precise, objective, and actionable information derived solely from the Elasticsearch data at your disposal.\n- Summarize key data points and trends based on user requests.\n\n**Reasoning Framework:**\n1.  **Understand:** Deconstruct the user's query to understand their core intent.\n2.  **Plan:** Formulate a step-by-step plan to answer the question. If you are unsure about the data structure, use the available tools to explore the indices first.\n3.  **Execute:** Use the available tools to execute your plan.\n4.  **Synthesize:** Combine the information from all tool calls into a single, comprehensive, and easy-to-read answer.\n\n**Key Directives and Constraints:**\n- **If a user's request is ambiguous, ask clarifying questions before proceeding.**\n- **DO NOT provide financial advice, recommendations, or predictions.** Your role is strictly informational and analytical.\n- Stay strictly on topic with financial data queries.\n- If you cannot answer a query, state that clearly and offer alternative ways you might help *within your data scope*.\n- All numerical values should be formatted appropriately (e.g., currency, percentages).\n\n**Output Format:**\n- All responses must be formatted using **Markdown** for clarity.\n- When presenting structured data, use Markdown tables, lists, or bolding.\n\n**Start by greeting the financial manager and offering assistance.**\n",
                "tools": [
                  {
                    "tool_ids": [
                      "platform.core.search",
                      "platform.core.list_indices",
                      "platform.core.get_index_mapping",
                      "platform.core.get_document_by_id",
                      "find_client_exposure_to_negative_news"
                    ]
                  }
                ]
              }
            }
          },
          "metadata": {
            "application/json": {
              "expanded": false,
              "root": "root"
            }
          }
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Section 4: The Payoff! — Chatting with the Agent\n",
        "\n",
        "Everything is now in place. We have our logic (the Tool) and our expert persona (the Agent). It's time to ask our `Financial Assistant` agent the complex, multi-step question from the blog post and see how it performs.\n",
        "\n",
        "We'll send our question to the `/api/agent_builder/converse` endpoint, making sure to specify our agent's ID."
      ],
      "metadata": {
        "id": "Pp90C3DWr_ap"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# First, define the complex question we want to ask.\n",
        "# user_question = \"Who has the highest account value and what is their highest valued individual asset?\"\n",
        "user_question = \"I'm worried about market sentiment. Can you show me which of our clients are most at risk from bad news?\"\n",
        "\n",
        "# Next, construct the request body for the /api/agent_builder/converse endpoint.\n",
        "# It's crucial that we specify the `agent_id` so we talk to our custom agent.\n",
        "chat_request_body = {\n",
        "    \"input\": user_question,\n",
        "    \"agent_id\": agent_id,  # Using the agent_id variable from the previous section\n",
        "}\n",
        "\n",
        "\n",
        "print(f\"✅ Chat request for agent '{agent_id}' is ready.\")\n",
        "display(JSON(chat_request_body))"
      ],
      "metadata": {
        "id": "nQ221TR1sDzJ",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 106
        },
        "outputId": "fd8a8324-1f32-43d9-8949-04268b770770"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Chat request for agent 'financial_assistant' is ready.\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.JSON object>"
            ],
            "application/json": {
              "input": "I'm worried about market sentiment. Can you show me which of our clients are most at risk from bad news?",
              "agent_id": "financial_assistant"
            }
          },
          "metadata": {
            "application/json": {
              "expanded": false,
              "root": "root"
            }
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Now, let's send the request and start the conversation!\n",
        "# This single API call will trigger the agent's complex reasoning process.\n",
        "\n",
        "display(Markdown(f\"### 💬 Asking: '{user_question}'\"))\n",
        "\n",
        "chat_response = None  # Initialize variable to store the response\n",
        "\n",
        "try:\n",
        "    response = requests.post(\n",
        "        f\"{kb_url}/api/agent_builder/converse\", headers=HEADERS, json=chat_request_body\n",
        "    )\n",
        "    response.raise_for_status()\n",
        "\n",
        "    chat_response = response.json()\n",
        "    print(\"✅ Agent responded successfully! See the analysis in the next cell.\")\n",
        "\n",
        "except requests.exceptions.RequestException as e:\n",
        "    print(f\"❌ Chat request failed: {e.response.text}\")"
      ],
      "metadata": {
        "id": "6Hvr9JSfsLsi",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 76
        },
        "outputId": "6647c5ba-001b-4fe8-a197-88db08410fc1"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "### 💬 Asking: 'I'm worried about market sentiment. Can you show me which of our clients are most at risk from bad news?'"
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Agent responded successfully! See the analysis in the next cell.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Analyzing the Response\n",
        "\n",
        "The agent's response contains three key parts:\n",
        "1.  **The Conversation ID:** A unique ID to continue this specific chat thread.\n",
        "2.  **The Final Message:** The human-readable answer, formatted in Markdown as we requested in our prompt.\n",
        "3.  **The Steps:** A detailed log of the agent's \"thought process,\" showing every tool it called and the parameters it used to arrive at the answer."
      ],
      "metadata": {
        "id": "CLAY9ZNSsPLN"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "chat_response[\"steps\"]"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "QwtC5PcUEynT",
        "outputId": "ea51f9de-668f-491d-d6f2-fb6693324e85"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[{'type': 'reasoning',\n",
              "  'reasoning': 'The user is concerned about market sentiment and wants to identify clients most at risk from negative news. The find_client_exposure_to_negative_news tool is specifically designed for this purpose, as it scans recent news for negative sentiment, identifies affected assets, and finds clients holding those assets.'},\n",
              " {'type': 'tool_call',\n",
              "  'tool_call_id': 'tooluse_ME2S2H88Qp-GXYBw3WaxNg',\n",
              "  'tool_id': 'find_client_exposure_to_negative_news',\n",
              "  'progression': [],\n",
              "  'params': {'time_duration': '24 hours'},\n",
              "  'results': [{'type': 'query',\n",
              "    'data': {'esql': '\\n        FROM financial_news, financial_reports METADATA _index\\n        | WHERE sentiment == \"negative\"\\n        | WHERE coalesce(published_date, report_date) >= NOW() - TO_TIMEDURATION(\"24 hours\")\\n        | RENAME primary_symbol AS symbol\\n        | LOOKUP JOIN financial_asset_details ON symbol\\n        | LOOKUP JOIN financial_holdings ON symbol\\n        | LOOKUP JOIN financial_accounts ON account_id\\n        | WHERE account_holder_name IS NOT NULL\\n        | EVAL position_current_value = quantity * current_price.price\\n        | RENAME title AS news_title\\n        | KEEP\\n            account_holder_name, symbol, asset_name, news_title,\\n            sentiment, position_current_value, quantity, current_price.price,\\n            published_date, report_date\\n        | SORT position_current_value DESC\\n        | LIMIT 50\\n      '}},\n",
              "   {'tool_result_id': 'zMEm',\n",
              "    'type': 'tabular_data',\n",
              "    'data': {'source': 'esql',\n",
              "     'query': '\\n        FROM financial_news, financial_reports METADATA _index\\n        | WHERE sentiment == \"negative\"\\n        | WHERE coalesce(published_date, report_date) >= NOW() - TO_TIMEDURATION(\"24 hours\")\\n        | RENAME primary_symbol AS symbol\\n        | LOOKUP JOIN financial_asset_details ON symbol\\n        | LOOKUP JOIN financial_holdings ON symbol\\n        | LOOKUP JOIN financial_accounts ON account_id\\n        | WHERE account_holder_name IS NOT NULL\\n        | EVAL position_current_value = quantity * current_price.price\\n        | RENAME title AS news_title\\n        | KEEP\\n            account_holder_name, symbol, asset_name, news_title,\\n            sentiment, position_current_value, quantity, current_price.price,\\n            published_date, report_date\\n        | SORT position_current_value DESC\\n        | LIMIT 50\\n      ',\n",
              "     'columns': [{'name': 'account_holder_name', 'type': 'text'},\n",
              "      {'name': 'symbol', 'type': 'keyword'},\n",
              "      {'name': 'asset_name', 'type': 'text'},\n",
              "      {'name': 'news_title', 'type': 'text'},\n",
              "      {'name': 'sentiment', 'type': 'keyword'},\n",
              "      {'name': 'position_current_value', 'type': 'double'},\n",
              "      {'name': 'quantity', 'type': 'double'},\n",
              "      {'name': 'current_price.price', 'type': 'double'},\n",
              "      {'name': 'published_date', 'type': 'date'},\n",
              "      {'name': 'report_date', 'type': 'date'}],\n",
              "     'values': [['Victoria Schneider',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       273680.0048828125,\n",
              "       200,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Jillian Davis',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       272311.60485839844,\n",
              "       199,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Lorraine Gibson',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       272311.60485839844,\n",
              "       199,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Craig Griffith',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       272311.60485839844,\n",
              "       199,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Jeffrey Byrd',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       270943.2048339844,\n",
              "       198,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Patrick Rice',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       270943.2048339844,\n",
              "       198,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Sophia Dean',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       270943.2048339844,\n",
              "       198,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Eileen Bailey',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       269574.8048095703,\n",
              "       197,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Sandra Nunez',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       269574.8048095703,\n",
              "       197,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Brandon Esparza',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       269574.8048095703,\n",
              "       197,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Miranda Vargas',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       269574.8048095703,\n",
              "       197,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Misty Gonzalez',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       269574.8048095703,\n",
              "       197,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Reginald Wang',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       268206.40478515625,\n",
              "       196,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Briana Mcclure',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       268206.40478515625,\n",
              "       196,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['James Miller',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       268206.40478515625,\n",
              "       196,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Meghan Parker',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       266838.0047607422,\n",
              "       195,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Lindsay Harris',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       266838.0047607422,\n",
              "       195,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Devin Hernandez',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       266838.0047607422,\n",
              "       195,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Jonathan Sullivan',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       265469.6047363281,\n",
              "       194,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Nicole Smith',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       264101.20471191406,\n",
              "       193,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Stephanie Sosa',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       264101.20471191406,\n",
              "       193,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Jamie Allen',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       264101.20471191406,\n",
              "       193,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Sharon Brown',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       262732.8046875,\n",
              "       192,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Joshua Shaw',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       262732.8046875,\n",
              "       192,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Terry Welch',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       262732.8046875,\n",
              "       192,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Clinton Greene',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       261364.40466308594,\n",
              "       191,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Karen Fisher',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       261364.40466308594,\n",
              "       191,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Angela Horn',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       261364.40466308594,\n",
              "       191,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Lauren Hatfield',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       258719.9951171875,\n",
              "       200,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Tracy Chambers',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       258719.9951171875,\n",
              "       200,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Tonya Bush',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       258719.9951171875,\n",
              "       200,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Cynthia Harris',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       258627.6046142578,\n",
              "       189,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['David Torres',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       258627.6046142578,\n",
              "       189,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Stacy Ellis',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       257426.39514160156,\n",
              "       199,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Jason Hill',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       257259.20458984375,\n",
              "       188,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Douglas Perry',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       256132.79516601562,\n",
              "       198,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['James Edwards',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       256132.79516601562,\n",
              "       198,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Crystal Reed',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       255890.8045654297,\n",
              "       187,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Amanda Fuller',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       255890.8045654297,\n",
              "       187,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Amber Hernandez',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       254839.1951904297,\n",
              "       197,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Madison Harper',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       254839.1951904297,\n",
              "       197,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Rebecca Bradley',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       253154.00451660156,\n",
              "       185,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Jose Marshall',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       252251.9952392578,\n",
              "       195,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Tiffany Walters',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       252251.9952392578,\n",
              "       195,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Tracy Thomas',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       252251.9952392578,\n",
              "       195,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Robert Bennett',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       251785.6044921875,\n",
              "       184,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Sarah Scott',\n",
              "       'TXN',\n",
              "       'Texas Instruments Inc.',\n",
              "       'TXN Tumbles on Major Cybersecurity Breach, IP at Risk',\n",
              "       'negative',\n",
              "       251785.6044921875,\n",
              "       184,\n",
              "       1368.4000244140625,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Ashley Walton',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       250958.39526367188,\n",
              "       194,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['Hailey Thomas',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       250958.39526367188,\n",
              "       194,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None],\n",
              "      ['George Richard',\n",
              "       'GM',\n",
              "       'General Motors Co.',\n",
              "       'GM Signals Trouble as Economic Slowdown Hits Auto Demand',\n",
              "       'negative',\n",
              "       250958.39526367188,\n",
              "       194,\n",
              "       1293.5999755859375,\n",
              "       '2025-09-23T04:29:29.000Z',\n",
              "       None]]}}]}]"
            ]
          },
          "metadata": {},
          "execution_count": 42
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "chat_response.keys()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "JdQlHM3eE_OE",
        "outputId": "11cf15f0-6c42-4965-cb0d-265634c7b50e"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "dict_keys(['conversation_id', 'steps', 'response'])"
            ]
          },
          "metadata": {},
          "execution_count": 37
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "steps = chat_response.get(\"steps\", [])\n",
        "for i, step in enumerate(steps):\n",
        "    print(step)\n",
        "    tool_id = step.get(\"tool_id\")\n",
        "    tool_params = step.get(\"params\", {})\n",
        "    display(Markdown(f\"**Step {i+1}: Call Tool `{tool_id}`**\"))\n",
        "    display(JSON(tool_params))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 204
        },
        "id": "_R9VYFeQFKe5",
        "outputId": "1fff3b45-2bdf-40a9-f15c-9474086beac3"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "{'type': 'reasoning', 'reasoning': 'The user is concerned about market sentiment and wants to identify clients most at risk from negative news. The find_client_exposure_to_negative_news tool is specifically designed for this purpose, as it scans recent news for negative sentiment, identifies affected assets, and finds clients holding those assets.'}\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "**Step 1: Call Tool `None`**"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.JSON object>"
            ],
            "application/json": {}
          },
          "metadata": {
            "application/json": {
              "expanded": false,
              "root": "root"
            }
          }
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "{'type': 'tool_call', 'tool_call_id': 'tooluse_ME2S2H88Qp-GXYBw3WaxNg', 'tool_id': 'find_client_exposure_to_negative_news', 'progression': [], 'params': {'time_duration': '24 hours'}, 'results': [{'type': 'query', 'data': {'esql': '\\n        FROM financial_news, financial_reports METADATA _index\\n        | WHERE sentiment == \"negative\"\\n        | WHERE coalesce(published_date, report_date) >= NOW() - TO_TIMEDURATION(\"24 hours\")\\n        | RENAME primary_symbol AS symbol\\n        | LOOKUP JOIN financial_asset_details ON symbol\\n        | LOOKUP JOIN financial_holdings ON symbol\\n        | LOOKUP JOIN financial_accounts ON account_id\\n        | WHERE account_holder_name IS NOT NULL\\n        | EVAL position_current_value = quantity * current_price.price\\n        | RENAME title AS news_title\\n        | KEEP\\n            account_holder_name, symbol, asset_name, news_title,\\n            sentiment, position_current_value, quantity, current_price.price,\\n            published_date, report_date\\n        | SORT position_current_value DESC\\n        | LIMIT 50\\n      '}}, {'tool_result_id': 'zMEm', 'type': 'tabular_data', 'data': {'source': 'esql', 'query': '\\n        FROM financial_news, financial_reports METADATA _index\\n        | WHERE sentiment == \"negative\"\\n        | WHERE coalesce(published_date, report_date) >= NOW() - TO_TIMEDURATION(\"24 hours\")\\n        | RENAME primary_symbol AS symbol\\n        | LOOKUP JOIN financial_asset_details ON symbol\\n        | LOOKUP JOIN financial_holdings ON symbol\\n        | LOOKUP JOIN financial_accounts ON account_id\\n        | WHERE account_holder_name IS NOT NULL\\n        | EVAL position_current_value = quantity * current_price.price\\n        | RENAME title AS news_title\\n        | KEEP\\n            account_holder_name, symbol, asset_name, news_title,\\n            sentiment, position_current_value, quantity, current_price.price,\\n            published_date, report_date\\n        | SORT position_current_value DESC\\n        | LIMIT 50\\n      ', 'columns': [{'name': 'account_holder_name', 'type': 'text'}, {'name': 'symbol', 'type': 'keyword'}, {'name': 'asset_name', 'type': 'text'}, {'name': 'news_title', 'type': 'text'}, {'name': 'sentiment', 'type': 'keyword'}, {'name': 'position_current_value', 'type': 'double'}, {'name': 'quantity', 'type': 'double'}, {'name': 'current_price.price', 'type': 'double'}, {'name': 'published_date', 'type': 'date'}, {'name': 'report_date', 'type': 'date'}], 'values': [['Victoria Schneider', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 273680.0048828125, 200, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Jillian Davis', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 272311.60485839844, 199, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Lorraine Gibson', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 272311.60485839844, 199, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Craig Griffith', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 272311.60485839844, 199, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Jeffrey Byrd', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 270943.2048339844, 198, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Patrick Rice', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 270943.2048339844, 198, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Sophia Dean', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 270943.2048339844, 198, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Eileen Bailey', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 269574.8048095703, 197, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Sandra Nunez', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 269574.8048095703, 197, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Brandon Esparza', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 269574.8048095703, 197, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Miranda Vargas', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 269574.8048095703, 197, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Misty Gonzalez', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 269574.8048095703, 197, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Reginald Wang', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 268206.40478515625, 196, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Briana Mcclure', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 268206.40478515625, 196, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['James Miller', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 268206.40478515625, 196, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Meghan Parker', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 266838.0047607422, 195, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Lindsay Harris', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 266838.0047607422, 195, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Devin Hernandez', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 266838.0047607422, 195, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Jonathan Sullivan', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 265469.6047363281, 194, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Nicole Smith', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 264101.20471191406, 193, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Stephanie Sosa', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 264101.20471191406, 193, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Jamie Allen', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 264101.20471191406, 193, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Sharon Brown', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 262732.8046875, 192, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Joshua Shaw', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 262732.8046875, 192, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Terry Welch', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 262732.8046875, 192, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Clinton Greene', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 261364.40466308594, 191, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Karen Fisher', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 261364.40466308594, 191, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Angela Horn', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 261364.40466308594, 191, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Lauren Hatfield', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 258719.9951171875, 200, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None], ['Tracy Chambers', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 258719.9951171875, 200, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None], ['Tonya Bush', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 258719.9951171875, 200, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None], ['Cynthia Harris', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 258627.6046142578, 189, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['David Torres', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 258627.6046142578, 189, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Stacy Ellis', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 257426.39514160156, 199, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None], ['Jason Hill', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 257259.20458984375, 188, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Douglas Perry', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 256132.79516601562, 198, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None], ['James Edwards', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 256132.79516601562, 198, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None], ['Crystal Reed', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 255890.8045654297, 187, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Amanda Fuller', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 255890.8045654297, 187, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Amber Hernandez', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 254839.1951904297, 197, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None], ['Madison Harper', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 254839.1951904297, 197, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None], ['Rebecca Bradley', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 253154.00451660156, 185, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Jose Marshall', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 252251.9952392578, 195, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None], ['Tiffany Walters', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 252251.9952392578, 195, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None], ['Tracy Thomas', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 252251.9952392578, 195, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None], ['Robert Bennett', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 251785.6044921875, 184, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Sarah Scott', 'TXN', 'Texas Instruments Inc.', 'TXN Tumbles on Major Cybersecurity Breach, IP at Risk', 'negative', 251785.6044921875, 184, 1368.4000244140625, '2025-09-23T04:29:29.000Z', None], ['Ashley Walton', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 250958.39526367188, 194, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None], ['Hailey Thomas', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 250958.39526367188, 194, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None], ['George Richard', 'GM', 'General Motors Co.', 'GM Signals Trouble as Economic Slowdown Hits Auto Demand', 'negative', 250958.39526367188, 194, 1293.5999755859375, '2025-09-23T04:29:29.000Z', None]]}}]}\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "**Step 2: Call Tool `find_client_exposure_to_negative_news`**"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.JSON object>"
            ],
            "application/json": {
              "time_duration": "24 hours"
            }
          },
          "metadata": {
            "application/json": {
              "expanded": false,
              "root": "root"
            }
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Let's parse the response from the previous cell and display each part clearly.\n",
        "\n",
        "if chat_response:\n",
        "    # 1. Print the Conversation ID\n",
        "    conversation_id = chat_response.get(\"conversation_id\")\n",
        "    display(Markdown(f\"### Conversation ID\\n`{conversation_id}`\"))\n",
        "\n",
        "    # 2. Display the final, formatted message\n",
        "    final_message = chat_response.get(\"response\", {}).get(\n",
        "        \"message\", \"No message found.\"\n",
        "    )\n",
        "    display(Markdown(\"---\"))\n",
        "    display(Markdown(f\"### Final Answer\\n{final_message}\"))\n",
        "    display(Markdown(\"---\"))\n",
        "\n",
        "    # 3. Show the agent's step-by-step reasoning\n",
        "    steps = chat_response.get(\"steps\", [])\n",
        "    display(Markdown(f\"### Agent's Reasoning: {len(steps)} Steps\"))\n",
        "\n",
        "    for i, step in enumerate(steps):\n",
        "        if step.get(\"type\") == \"reasoning\":\n",
        "            display(Markdown(f\"**Step {i+1}: Call Tool is Reasoning**\"))\n",
        "            display(step.get(\"reasoning\"))\n",
        "        elif step.get(\"type\") == \"tool_call\":\n",
        "            tool_id = step.get(\"tool_id\")\n",
        "            tool_params = step.get(\"params\", {})\n",
        "            display(Markdown(f\"**Step {i+1}: Call Tool `{tool_id}`**\"))\n",
        "            display(JSON(tool_params))\n",
        "\n",
        "else:\n",
        "    print(\n",
        "        \"⚠️ Chat response variable is empty. Please run the previous cell successfully.\"\n",
        "    )"
      ],
      "metadata": {
        "id": "gDTpr2JksNPf",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "0182504b-6199-4180-84e1-6bb4c5b29f76"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "### Conversation ID\n`5a6e7969-6a67-43cb-a3c7-fc12c83ff122`"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "---"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "### Final Answer\n# Client Exposure to Negative News - Last 24 Hours\n\n## Key Findings\n\nI've analyzed the market for negative news in the past 24 hours and identified two major issues affecting our clients:\n\n1. **Texas Instruments (TXN)** - Major cybersecurity breach with intellectual property at risk\n2. **General Motors (GM)** - Economic slowdown impacting auto demand\n\n## Clients with Highest Exposure\n\n### Texas Instruments (TXN) - Current Price: $1,368.40\n\n| Client Name | Position Value ($) | Shares |\n|-------------|------------------:|-------:|\n| Victoria Schneider | 273,680.00 | 200 |\n| Jillian Davis | 272,311.60 | 199 |\n| Lorraine Gibson | 272,311.60 | 199 |\n| Craig Griffith | 272,311.60 | 199 |\n| Jeffrey Byrd | 270,943.20 | 198 |\n\n### General Motors (GM) - Current Price: $1,293.60\n\n| Client Name | Position Value ($) | Shares |\n|-------------|------------------:|-------:|\n| Lauren Hatfield | 258,720.00 | 200 |\n| Tracy Chambers | 258,720.00 | 200 |\n| Tonya Bush | 258,720.00 | 200 |\n| Stacy Ellis | 257,426.40 | 199 |\n| Douglas Perry | 256,132.80 | 198 |\n\n## Summary\n\nA total of 50 clients have significant exposure to these negative news events. The most affected clients hold positions valued between $250,000 and $274,000. The Texas Instruments cybersecurity breach appears to be affecting more clients with higher position values than the General Motors economic slowdown news.\n\n<visualization tool-result-id=\"zMEm\" />"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "---"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "### Agent's Reasoning: 2 Steps"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "**Step 1: Call Tool is Reasoning**"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "'The user is concerned about market sentiment and wants to identify clients most at risk from negative news. The find_client_exposure_to_negative_news tool is specifically designed for this purpose, as it scans recent news for negative sentiment, identifies affected assets, and finds clients holding those assets.'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "**Step 2: Call Tool `find_client_exposure_to_negative_news`**"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.JSON object>"
            ],
            "application/json": {
              "time_duration": "24 hours"
            }
          },
          "metadata": {
            "application/json": {
              "expanded": false,
              "root": "root"
            }
          }
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Section 5: Next Steps\n",
        "\n",
        "You've successfully built and chatted with a custom AI agent! This final section covers:\n",
        "1.  **Continuing a Conversation:** How to ask follow-up questions while maintaining the chat's context.\n",
        "2.  **History**: How to retrieve conversation history\n"
      ],
      "metadata": {
        "id": "7vpozNy6salb"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Continuing a Conversation\n",
        "The `conversation_id` returned from our first chat request is the key to memory. By including it in subsequent requests, you tell the agent to consider the previous turns of the conversation for context."
      ],
      "metadata": {
        "id": "17w7-YLmsfbp"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Let's ask a follow-up question using the conversation_id from the previous section.\n",
        "\n",
        "if \"conversation_id\" in locals() and conversation_id:\n",
        "    follow_up_question = \"Summarize the first article mentioned.\"\n",
        "\n",
        "    follow_up_body = {\n",
        "        \"input\": follow_up_question,\n",
        "        \"conversation_id\": conversation_id,\n",
        "        # No agent_id is needed, as it's tied to the conversation\n",
        "    }\n",
        "\n",
        "    display(Markdown(f\"### 💬 Asking Follow-up: '{follow_up_question}'\"))\n",
        "\n",
        "    try:\n",
        "        response = requests.post(\n",
        "            f\"{kb_url}/api/agent_builder/converse\", headers=HEADERS, json=follow_up_body\n",
        "        )\n",
        "        response.raise_for_status()\n",
        "\n",
        "        follow_up_response = response.json()\n",
        "        final_message = follow_up_response.get(\"response\", {}).get(\n",
        "            \"message\", \"No message found.\"\n",
        "        )\n",
        "\n",
        "        # MODIFICATION: Wrap the final message in a code block for clean formatting\n",
        "        display(Markdown(f\"### Follow-up Answer\\n\\n```text\\n{final_message}\\n```\"))\n",
        "\n",
        "    except requests.exceptions.RequestException as e:\n",
        "        print(f\"❌ Chat request failed: {e.response.text}\")\n",
        "else:\n",
        "    print(\"⚠️ `conversation_id` not found. Please run Section 4 successfully first.\")"
      ],
      "metadata": {
        "id": "XNwJiz6DsdF1",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 548
        },
        "outputId": "6d280892-f0b7-4923-d580-3057bc907993"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "### 💬 Asking Follow-up: 'Summarize the first article mentioned.'"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "### Follow-up Answer\n\n```text\n# Summary: TXN Tumbles on Major Cybersecurity Breach, IP at Risk\n\nTexas Instruments (TXN) has confirmed a significant cybersecurity breach where unauthorized actors gained access to the company's internal servers. According to the article published on September 23, 2025:\n\n## Key Points:\n\n- Unauthorized actors accessed Texas Instruments' internal servers\n- Early reports suggest sensitive intellectual property was compromised, including:\n  - Proprietary chip designs\n  - Customer data\n\n- The full extent of the breach is still under investigation\n- Texas Instruments has:\n  - Engaged leading cybersecurity firms\n  - Started cooperating with federal authorities\n\n## Market Impact:\n\n- TXN stock tumbled in pre-market trading\n- Investors are concerned about:\n  - Potential reputational damage\n  - Competitive disadvantage from stolen intellectual property\n  - Costly remediation efforts\n\nThe incident has raised serious concerns about security vulnerabilities in critical supply chains within the technology sector.\n```"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Retrieving Conversation History\n",
        "You can also retrieve the full history of any conversation using its ID."
      ],
      "metadata": {
        "id": "CIk8Wa-Esj5k"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Fetch the full history for our conversation\n",
        "\n",
        "if \"conversation_id\" in locals() and conversation_id:\n",
        "    display(\n",
        "        Markdown(\n",
        "            f\"### 📖 Retrieving Full History for Conversation:\\n`{conversation_id}`\"\n",
        "        )\n",
        "    )\n",
        "    try:\n",
        "        response = requests.get(\n",
        "            f\"{kb_url}/api/agent_builder/conversations/{conversation_id}\",\n",
        "            headers=HEADERS,\n",
        "        )\n",
        "        response.raise_for_status()\n",
        "\n",
        "        display(JSON(response.json()))\n",
        "\n",
        "    except requests.exceptions.RequestException as e:\n",
        "        print(f\"❌ Could not retrieve conversation: {e.response.text}\")\n",
        "else:\n",
        "    print(\"⚠️ `conversation_id` not found. Please run Section 4 successfully first.\")"
      ],
      "metadata": {
        "id": "s-D1DYUJsiM3",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "9ea7112c-5ddb-4011-e770-8062500160ea"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "### 📖 Retrieving Full History for Conversation:\n`5a6e7969-6a67-43cb-a3c7-fc12c83ff122`"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.JSON object>"
            ],
            "application/json": {
              "id": "5a6e7969-6a67-43cb-a3c7-fc12c83ff122",
              "agent_id": "financial_assistant",
              "user": {
                "username": "3953873479"
              },
              "title": "Client Risk Assessment Due to Market Sentiment",
              "created_at": "2025-09-23T05:32:04.689Z",
              "updated_at": "2025-09-23T05:32:04.689Z",
              "rounds": [
                {
                  "id": "1e5d28f4-9809-4978-b04c-b070a7f5c70a",
                  "input": {
                    "message": "I'm worried about market sentiment. Can you show me which of our clients are most at risk from bad news?"
                  },
                  "steps": [
                    {
                      "type": "reasoning",
                      "reasoning": "The user is concerned about market sentiment and wants to identify clients most at risk from negative news. The find_client_exposure_to_negative_news tool is specifically designed for this purpose, as it scans recent news for negative sentiment, identifies affected assets, and finds clients holding those assets."
                    },
                    {
                      "type": "tool_call",
                      "tool_call_id": "tooluse_ME2S2H88Qp-GXYBw3WaxNg",
                      "tool_id": "find_client_exposure_to_negative_news",
                      "progression": [],
                      "params": {
                        "time_duration": "24 hours"
                      },
                      "results": [
                        {
                          "type": "query",
                          "data": {
                            "esql": "\n        FROM financial_news, financial_reports METADATA _index\n        | WHERE sentiment == \"negative\"\n        | WHERE coalesce(published_date, report_date) >= NOW() - TO_TIMEDURATION(\"24 hours\")\n        | RENAME primary_symbol AS symbol\n        | LOOKUP JOIN financial_asset_details ON symbol\n        | LOOKUP JOIN financial_holdings ON symbol\n        | LOOKUP JOIN financial_accounts ON account_id\n        | WHERE account_holder_name IS NOT NULL\n        | EVAL position_current_value = quantity * current_price.price\n        | RENAME title AS news_title\n        | KEEP\n            account_holder_name, symbol, asset_name, news_title,\n            sentiment, position_current_value, quantity, current_price.price,\n            published_date, report_date\n        | SORT position_current_value DESC\n        | LIMIT 50\n      "
                          }
                        },
                        {
                          "tool_result_id": "zMEm",
                          "type": "tabular_data",
                          "data": {
                            "source": "esql",
                            "query": "\n        FROM financial_news, financial_reports METADATA _index\n        | WHERE sentiment == \"negative\"\n        | WHERE coalesce(published_date, report_date) >= NOW() - TO_TIMEDURATION(\"24 hours\")\n        | RENAME primary_symbol AS symbol\n        | LOOKUP JOIN financial_asset_details ON symbol\n        | LOOKUP JOIN financial_holdings ON symbol\n        | LOOKUP JOIN financial_accounts ON account_id\n        | WHERE account_holder_name IS NOT NULL\n        | EVAL position_current_value = quantity * current_price.price\n        | RENAME title AS news_title\n        | KEEP\n            account_holder_name, symbol, asset_name, news_title,\n            sentiment, position_current_value, quantity, current_price.price,\n            published_date, report_date\n        | SORT position_current_value DESC\n        | LIMIT 50\n      ",
                            "columns": [
                              {
                                "name": "account_holder_name",
                                "type": "text"
                              },
                              {
                                "name": "symbol",
                                "type": "keyword"
                              },
                              {
                                "name": "asset_name",
                                "type": "text"
                              },
                              {
                                "name": "news_title",
                                "type": "text"
                              },
                              {
                                "name": "sentiment",
                                "type": "keyword"
                              },
                              {
                                "name": "position_current_value",
                                "type": "double"
                              },
                              {
                                "name": "quantity",
                                "type": "double"
                              },
                              {
                                "name": "current_price.price",
                                "type": "double"
                              },
                              {
                                "name": "published_date",
                                "type": "date"
                              },
                              {
                                "name": "report_date",
                                "type": "date"
                              }
                            ],
                            "values": [
                              [
                                "Victoria Schneider",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                273680.0048828125,
                                200,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Jillian Davis",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                272311.60485839844,
                                199,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Lorraine Gibson",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                272311.60485839844,
                                199,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Craig Griffith",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                272311.60485839844,
                                199,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Jeffrey Byrd",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                270943.2048339844,
                                198,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Patrick Rice",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                270943.2048339844,
                                198,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Sophia Dean",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                270943.2048339844,
                                198,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Eileen Bailey",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                269574.8048095703,
                                197,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Sandra Nunez",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                269574.8048095703,
                                197,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Brandon Esparza",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                269574.8048095703,
                                197,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Miranda Vargas",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                269574.8048095703,
                                197,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Misty Gonzalez",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                269574.8048095703,
                                197,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Reginald Wang",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                268206.40478515625,
                                196,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Briana Mcclure",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                268206.40478515625,
                                196,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "James Miller",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                268206.40478515625,
                                196,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Meghan Parker",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                266838.0047607422,
                                195,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Lindsay Harris",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                266838.0047607422,
                                195,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Devin Hernandez",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                266838.0047607422,
                                195,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Jonathan Sullivan",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                265469.6047363281,
                                194,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Nicole Smith",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                264101.20471191406,
                                193,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Stephanie Sosa",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                264101.20471191406,
                                193,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Jamie Allen",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                264101.20471191406,
                                193,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Sharon Brown",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                262732.8046875,
                                192,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Joshua Shaw",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                262732.8046875,
                                192,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Terry Welch",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                262732.8046875,
                                192,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Clinton Greene",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                261364.40466308594,
                                191,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Karen Fisher",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                261364.40466308594,
                                191,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Angela Horn",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                261364.40466308594,
                                191,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Lauren Hatfield",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                258719.9951171875,
                                200,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Tracy Chambers",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                258719.9951171875,
                                200,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Tonya Bush",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                258719.9951171875,
                                200,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Cynthia Harris",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                258627.6046142578,
                                189,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "David Torres",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                258627.6046142578,
                                189,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Stacy Ellis",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                257426.39514160156,
                                199,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Jason Hill",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                257259.20458984375,
                                188,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Douglas Perry",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                256132.79516601562,
                                198,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "James Edwards",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                256132.79516601562,
                                198,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Crystal Reed",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                255890.8045654297,
                                187,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Amanda Fuller",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                255890.8045654297,
                                187,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Amber Hernandez",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                254839.1951904297,
                                197,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Madison Harper",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                254839.1951904297,
                                197,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Rebecca Bradley",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                253154.00451660156,
                                185,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Jose Marshall",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                252251.9952392578,
                                195,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Tiffany Walters",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                252251.9952392578,
                                195,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Tracy Thomas",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                252251.9952392578,
                                195,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Robert Bennett",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                251785.6044921875,
                                184,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Sarah Scott",
                                "TXN",
                                "Texas Instruments Inc.",
                                "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                                "negative",
                                251785.6044921875,
                                184,
                                1368.4000244140625,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Ashley Walton",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                250958.39526367188,
                                194,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "Hailey Thomas",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                250958.39526367188,
                                194,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ],
                              [
                                "George Richard",
                                "GM",
                                "General Motors Co.",
                                "GM Signals Trouble as Economic Slowdown Hits Auto Demand",
                                "negative",
                                250958.39526367188,
                                194,
                                1293.5999755859375,
                                "2025-09-23T04:29:29.000Z",
                                null
                              ]
                            ]
                          }
                        }
                      ]
                    }
                  ],
                  "response": {
                    "message": "# Client Exposure to Negative News - Last 24 Hours\n\n## Key Findings\n\nI've analyzed the market for negative news in the past 24 hours and identified two major issues affecting our clients:\n\n1. **Texas Instruments (TXN)** - Major cybersecurity breach with intellectual property at risk\n2. **General Motors (GM)** - Economic slowdown impacting auto demand\n\n## Clients with Highest Exposure\n\n### Texas Instruments (TXN) - Current Price: $1,368.40\n\n| Client Name | Position Value ($) | Shares |\n|-------------|------------------:|-------:|\n| Victoria Schneider | 273,680.00 | 200 |\n| Jillian Davis | 272,311.60 | 199 |\n| Lorraine Gibson | 272,311.60 | 199 |\n| Craig Griffith | 272,311.60 | 199 |\n| Jeffrey Byrd | 270,943.20 | 198 |\n\n### General Motors (GM) - Current Price: $1,293.60\n\n| Client Name | Position Value ($) | Shares |\n|-------------|------------------:|-------:|\n| Lauren Hatfield | 258,720.00 | 200 |\n| Tracy Chambers | 258,720.00 | 200 |\n| Tonya Bush | 258,720.00 | 200 |\n| Stacy Ellis | 257,426.40 | 199 |\n| Douglas Perry | 256,132.80 | 198 |\n\n## Summary\n\nA total of 50 clients have significant exposure to these negative news events. The most affected clients hold positions valued between $250,000 and $274,000. The Texas Instruments cybersecurity breach appears to be affecting more clients with higher position values than the General Motors economic slowdown news.\n\n<visualization tool-result-id=\"zMEm\" />"
                  }
                },
                {
                  "id": "4ea485ff-f183-488b-a5de-be7d34fbd766",
                  "input": {
                    "message": "Summarize the first article mentioned."
                  },
                  "steps": [
                    {
                      "type": "reasoning",
                      "reasoning": "I need to find the full content of the article about Texas Instruments (TXN) mentioned in the previous results to provide a summary."
                    },
                    {
                      "type": "tool_call",
                      "tool_call_id": "tooluse_Ib9yNGq1RBaata0Ee9I_Sg",
                      "tool_id": "platform.core.search",
                      "progression": [
                        {
                          "message": "Selecting the best target for this query"
                        },
                        {
                          "message": "Selected \"financial_news\" as the next search target"
                        },
                        {
                          "message": "Thinking about the search strategy to use"
                        },
                        {
                          "message": "Searching documents for \"TXN Tumbles on Major Cybersecurity Breach, IP at Risk\""
                        }
                      ],
                      "params": {
                        "query": "TXN Tumbles on Major Cybersecurity Breach, IP at Risk"
                      },
                      "results": [
                        {
                          "type": "resource",
                          "data": {
                            "reference": {
                              "id": "6c68e55c-b880-4c56-ba22-d9f65abb20c9",
                              "index": "financial_news"
                            },
                            "partial": true,
                            "content": {
                              "highlights": [
                                "<em>TXN</em> <em>Tumbles</em> <em>on</em> <em>Major</em> <em>Cybersecurity</em> <em>Breach</em>, <em>IP</em> <em>at</em> <em>Risk</em>",
                                "Texas Instruments (<em>TXN</em>) confirmed this morning it has suffered a significant <em>cybersecurity</em> <em>breach</em>, sending",
                                "The full extent of the <em>breach</em> is currently under investigation.",
                                "Texas Instruments has engaged leading <em>cybersecurity</em> firms and is cooperating with federal authorities",
                                "reacting negatively to the potential for reputational damage, competitive disadvantage from stolen <em>IP</em>"
                              ]
                            }
                          }
                        },
                        {
                          "type": "resource",
                          "data": {
                            "reference": {
                              "id": "efd320dc-7501-4941-87e0-c670fc70808a",
                              "index": "financial_news"
                            },
                            "partial": true,
                            "content": {
                              "highlights": [
                                "Walgreens Reels from <em>Major</em> <em>Cybersecurity</em> <em>Breach</em>, Customer Data <em>at</em> <em>Risk</em>",
                                "Walgreens Boots Alliance Inc. confirmed this morning it has suffered a significant <em>cybersecurity</em> <em>breach</em>",
                                "The <em>breach</em> could lead to substantial regulatory fines and costly litigation."
                              ]
                            }
                          }
                        },
                        {
                          "type": "resource",
                          "data": {
                            "reference": {
                              "id": "cc05d0c0-ae02-4c3f-8b3d-7c09d30974e4",
                              "index": "financial_news"
                            },
                            "partial": true,
                            "content": {
                              "highlights": [
                                "Tech Sector Scrutinized After <em>Breach</em> <em>at</em> <em>Major</em> QQQ Component",
                                "The technology sector faces renewed scrutiny after a significant <em>cybersecurity</em> <em>breach</em> was disclosed by",
                                "Details of the <em>breach</em> are still emerging, but the incident highlights potential vulnerabilities within",
                                "While the affected company's stock saw a sharp decline, the impact <em>on</em> the broader QQQ ETF has been muted",
                                "Analysts note the fund's diversification across 100 of the largest non-financial companies <em>on</em> the Nasdaq",
                                "However, investors remain watchful for any potential contagion effect or a broader reassessment of <em>risk</em>"
                              ]
                            }
                          }
                        },
                        {
                          "type": "resource",
                          "data": {
                            "reference": {
                              "id": "c69ec94f-506a-4c7a-a891-3e0d4896e7c2",
                              "index": "financial_news"
                            },
                            "partial": true,
                            "content": {
                              "highlights": [
                                "Labor disputes <em>at</em> <em>major</em> ports and geopolitical tensions are creating fresh bottlenecks, threatening to",
                                "The easing of some pressures could help temper inflationary forces, but the new disruptions <em>risk</em> reversing"
                              ]
                            }
                          }
                        },
                        {
                          "type": "resource",
                          "data": {
                            "reference": {
                              "id": "83525471-2ae5-46fe-a830-39b71babd136",
                              "index": "financial_news"
                            },
                            "partial": true,
                            "content": {
                              "highlights": [
                                "Global markets are <em>on</em> edge as escalating geopolitical tensions threaten to unravel established trade",
                                "Renewed friction between <em>major</em> economic blocs has sparked concerns over fresh supply chain disruptions",
                                "While the near-term outlook is fraught with <em>risk</em>, ongoing diplomatic talks offer a glimmer of hope, leaving"
                              ]
                            }
                          }
                        },
                        {
                          "type": "resource",
                          "data": {
                            "reference": {
                              "id": "2fbfc5a3-ea08-489c-a36b-512fdc5ebd90",
                              "index": "financial_news"
                            },
                            "partial": true,
                            "content": {
                              "highlights": [
                                "Global markets are <em>on</em> edge as a sudden surge in energy prices threatens to derail economic stability.",
                                "translated into higher transportation and manufacturing costs, squeezing corporate profit margins across <em>major</em>",
                                "Consumers are also feeling the pinch <em>at</em> the pump and <em>on</em> their utility bills, stoking fears of a slowdown",
                                "could reignite stubborn inflationary pressures, potentially complicating central bank policies aimed <em>at</em>"
                              ]
                            }
                          }
                        },
                        {
                          "type": "resource",
                          "data": {
                            "reference": {
                              "id": "dece1a11-f870-4e5c-8a8d-ad397f915ee7",
                              "index": "financial_news"
                            },
                            "partial": true,
                            "content": {
                              "highlights": [
                                "Hopes for a swift return to price stability have faded, as the rising cost of living continues to be a <em>major</em>",
                                "Renewed market anxiety centers <em>on</em> the possibility of more aggressive interest rate hikes to combat rising",
                                "prices, a policy that could <em>risk</em> slowing economic growth and increasing the likelihood of a recession"
                              ]
                            }
                          }
                        },
                        {
                          "type": "resource",
                          "data": {
                            "reference": {
                              "id": "65e2c416-c4a1-4753-90af-b2650a6397af",
                              "index": "financial_news"
                            },
                            "partial": true,
                            "content": {
                              "highlights": [
                                "Energy Markets <em>at</em> a Crossroads Amid Supply Jitters",
                                "A recent dip in crude oil prices has provided some relief to consumers <em>at</em> the pump and eased inflationary",
                                "pressures <em>on</em> businesses, largely attributed to signs of slowing economic activity in <em>major</em> economies",
                                "Analysts remain divided <em>on</em> the future trajectory, leaving businesses and policymakers navigating a clouded"
                              ]
                            }
                          }
                        },
                        {
                          "type": "resource",
                          "data": {
                            "reference": {
                              "id": "cb72648e-5a8c-42e5-9dee-304fd291e632",
                              "index": "financial_news"
                            },
                            "partial": true,
                            "content": {
                              "highlights": [
                                "Danaher Faces Patent Challenge Over Biotechnology <em>IP</em>",
                                "Analysts are monitoring the situation for potential implications <em>on</em> the segment's operations, though",
                                "the ultimate financial impact remains uncertain <em>at</em> this early stage."
                              ]
                            }
                          }
                        },
                        {
                          "type": "resource",
                          "data": {
                            "reference": {
                              "id": "91bb392a-7990-4dd9-99af-6904019ab9a8",
                              "index": "financial_news"
                            },
                            "partial": true,
                            "content": {
                              "highlights": [
                                "A significant diplomatic breakthrough between <em>major</em> economic powers is sending waves of optimism through",
                                "Investors are reacting positively to the reduced geopolitical <em>risk</em>, anticipating a period of more stable"
                              ]
                            }
                          }
                        }
                      ]
                    },
                    {
                      "type": "reasoning",
                      "reasoning": "I need to retrieve the full content of the Texas Instruments cybersecurity breach article to provide a complete summary."
                    },
                    {
                      "type": "tool_call",
                      "tool_call_id": "tooluse_Lo_BR2HJSCKkJt-Fe437qw",
                      "tool_id": "platform.core.get_document_by_id",
                      "progression": [],
                      "params": {
                        "id": "6c68e55c-b880-4c56-ba22-d9f65abb20c9",
                        "index": "financial_news"
                      },
                      "results": [
                        {
                          "type": "resource",
                          "data": {
                            "reference": {
                              "id": "6c68e55c-b880-4c56-ba22-d9f65abb20c9",
                              "index": "financial_news"
                            },
                            "partial": false,
                            "content": {
                              "article_id": "6c68e55c-b880-4c56-ba22-d9f65abb20c9",
                              "title": "TXN Tumbles on Major Cybersecurity Breach, IP at Risk",
                              "content": "Texas Instruments (TXN) confirmed this morning it has suffered a significant cybersecurity breach, sending its stock tumbling in pre-market trading. The semiconductor giant stated that unauthorized actors gained access to its internal servers, with early reports suggesting sensitive intellectual property, including proprietary chip designs and customer data, may have been compromised. The full extent of the breach is currently under investigation.\n\nThe incident raises serious concerns about the security of critical supply chains within the technology sector. Texas Instruments has engaged leading cybersecurity firms and is cooperating with federal authorities. Investors are reacting negatively to the potential for reputational damage, competitive disadvantage from stolen IP, and costly remediation efforts.",
                              "source": "Reuters",
                              "published_date": "2025-09-23T04:29:29",
                              "url": "http://fakenews.com/article/2f4abc0b",
                              "entities": [
                                "Texas Instruments Inc.",
                                "TXN",
                                "Technology"
                              ],
                              "sentiment": "negative",
                              "last_updated": "2025-09-23T04:29:29",
                              "primary_symbol": "TXN",
                              "company_symbol": null
                            }
                          }
                        }
                      ]
                    }
                  ],
                  "response": {
                    "message": "# Summary: TXN Tumbles on Major Cybersecurity Breach, IP at Risk\n\nTexas Instruments (TXN) has confirmed a significant cybersecurity breach where unauthorized actors gained access to the company's internal servers. According to the article published on September 23, 2025:\n\n## Key Points:\n\n- Unauthorized actors accessed Texas Instruments' internal servers\n- Early reports suggest sensitive intellectual property was compromised, including:\n  - Proprietary chip designs\n  - Customer data\n\n- The full extent of the breach is still under investigation\n- Texas Instruments has:\n  - Engaged leading cybersecurity firms\n  - Started cooperating with federal authorities\n\n## Market Impact:\n\n- TXN stock tumbled in pre-market trading\n- Investors are concerned about:\n  - Potential reputational damage\n  - Competitive disadvantage from stolen intellectual property\n  - Costly remediation efforts\n\nThe incident has raised serious concerns about security vulnerabilities in critical supply chains within the technology sector."
                  }
                }
              ]
            }
          },
          "metadata": {
            "application/json": {
              "expanded": false,
              "root": "root"
            }
          }
        }
      ]
    }
  ]
}
